PAT 1120. 朋友数
原题链接
简单
作者:
YAX_AC
,
2024-11-18 16:58:18
,
所有人可见
,
阅读 2
// print in the first line the number of
//different friend ID's among the given integers
//输出给定数字中不同的朋友证号的个数
//Then in the second line, output the friend ID's in increasing order.
//The numbers must be separated by exactly one space
//and there must be no extra space at the end of the line.
//随后一行按递增顺序输出这些朋友证号,数字间隔一个空格,且行末不得有多余空格。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
int n;
set<int> S;
int main()
{
cin>>n;
for(int i = 0; i<n; i++)
{
int x;
cin>>x;
int sum = 0;
while(x)
{
sum+=x%10;
x/=10;
}
S.insert(sum);
}
cout<<S.size()<<endl;
bool is_first = true;
for(auto i:S)
{
if(is_first) is_first = false;
else cout<<' ';
cout<<i;
}
return 0;
}