版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Nightmare_ak/article/details/84799213
#include<cstdio>
#include<vector>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;
map<int, int> mp;
vector<int> ans;
int main()
{
int n; scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
char s[10];
scanf("%s", s);
int len = strlen(s), sum = 0;
for (int i = 0; i<len; i++)
sum += s[i] - '0';
mp[sum]++;
}
for (auto it : mp)
if (it.second > 0)
ans.push_back(it.first);
ans.resize(unique(ans.begin(), ans.end()) - ans.begin());
printf("%d\n", ans.size());
for (int i = 0; i < ans.size(); i++)
printf("%d%c", ans[i], " \n"[i + 1 == ans.size()]);
return 0;
}