题目翻译:
给出一个十进制数,其所有位的和是它的ID,ID相同的数叫朋友数。给出N
个数字,求有几个不同的ID,并将这些ID排序输出。
题解思路:
用map存储ID即可,确保唯一性
代码:
#include<bits/stdc++.h>
using namespace std;
map<int, bool> p;
void tofriend(string n)
{
int temp = 0;
for (int i = 0;i < n.size();i++)
temp += n[i] - '0';
p[temp] = 1;
}
int main()
{
int N;
cin >> N;
while (N--)
{
string t;
cin >> t;
tofriend(t);
}
cout << p.size() << endl;
for (auto i = p.begin();i != p.end();i++)
{
if (i != p.begin())
cout << " ";
cout << i->first;
}
}
坑点:
无