用string然后按位相加丢到set里面就好了~
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#define MAX 10010
using namespace std;
int n;
set <int> ans;
vector <int> finans;
int convert(string s) {
int sum = 0;
for (int i = 0; i < s.size(); i++) {
sum += int(s[i] - '0');
}
return sum;
}
int main() {
cin >> n;
string temp;
for (int i = 0; i < n; i++) {
cin >> temp;
int id = convert(temp);
ans.insert(id);
}
set <int>::iterator it;
for (it = ans.begin(); it != ans.end(); it++) {
finans.push_back(*it);
}
sort(finans.begin(), finans.end());
cout << finans.size() << endl;
for (int i = 0; i < finans.size() - 1; i++) {
cout << finans[i] << " ";
}
cout << finans[finans.size() - 1] << endl;
return 0;
}