1064
2017-09-05 本文已影响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;
}