【PTA-1120】 朋友数
分析: 简单Hash
#include <iostream>
#include <set>
using namespace std;
int main(int argc, char const *argv[])
{
int n;
cin >> n;
set<int> S;
while (n--)
{
int x;
cin >> x;
int s = 0;
while (x)
s += x % 10, x /= 10;
S.insert(s);
}
cout << S.size() << endl;
bool is_first = true;
for (auto x : S)
{
if (is_first)
is_first = false;
else
cout << ' ';
cout << x;
}
return 0;
}