首页 > 其他 > 详细

1064 朋友数 (20 分)

时间:2019-04-29 10:14:38      阅读:131      评论:0      收藏:0      [点我收藏+]
#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 分)

原文:https://www.cnblogs.com/Hk456/p/10788375.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!