1064 朋友数 (20 分)

Posted hk456

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1064 朋友数 (20 分)相关的知识,希望对你有一定的参考价值。

#include <iostream>
#include <set>   // set 集合中没有重复的元素
using namespace std;
int cmp(int t) {
    int sum = 0;
    while (t != 0) {
        sum += t % 10;
        t /= 10;
    }
    return sum;
}
int main() {
    int n, x;
    set <int> st;
    cin >> n;
    while (n--) {
        cin >> x;
        st.insert(cmp(x));  
    }
    cout << st.size() << endl;
    for (auto it = st.begin(); it != st.end(); it++) {   // auto自动推断变量类型
        if (it != st.begin()) {
            cout <<  ;
        }
        cout << *it;
    }
    cout << endl;
    return 0;
}

 

以上是关于1064 朋友数 (20 分)的主要内容,如果未能解决你的问题,请参考以下文章

PAT乙级1064 朋友数 (20 分)

1064. 朋友数(20)

1064. 朋友数(20)

PAT 1064. 朋友数(20)

PAT 1064. 朋友数

1064 朋友数