1064

作者: 峡迩 | 来源:发表于2017-09-05 13:06 被阅读0次
    // PATn.cpp : 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include<iostream>
    #include<set>
    
    
    using namespace std;
    
    
    unsigned get_friend(unsigned n)
    {
        unsigned ret = 0;
        while (n>0)
        {
            ret = ret + n % 10;
            n = n / 10;
        }
        return ret;
    }
    
    int main()
    {
        unsigned n;
        cin >> n;
    
        set<unsigned> data;
    
        for (unsigned i = 0; i < n; ++i)
        {
            unsigned tmp;
            cin >> tmp;
            data.insert(get_friend(tmp));
        }
    
        cout << data.size() << endl;
        auto beg = data.cbegin();           //set的值为key,可以通过迭代器访问!find是查找是否有某元素!
        for (size_t i = 0; i < data.size(); ++i)
        {
            cout << *beg;
            ++beg;
            
            if (i != (data.size() - 1))
                cout << " ";
        }
    
        system("pause");
        return 0;
    }
    
    

    相关文章

      网友评论

          本文标题:1064

          本文链接:https://www.haomeiwen.com/subject/gquujxtx.html