1120 Friend Numbers (20 分)(进制转换水题)

#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <vector>
#include <set>
#include <cmath>
using namespace std;

set<int> ans;

int main() 
{
	int n;
	cin >> n;
	for (int i = 0; i<n; i++) {
		int t, sum = 0;
		cin >> t;
		while (t) {
			sum += t%10;
			t /= 10;
		}
		ans.insert(sum);
	}
	cout << ans.size() << endl;
	
	set<int>::iterator it;
	
	for (it = ans.begin(); it != ans.end(); it++) {
		if (it == ans.begin()) {
			printf("%d", *it);
		} else {
			printf(" %d", *it);
		}
	}
	
	cout << endl;
	
	return 0;
}
上一篇:1120


下一篇:1120 Friend Numbers (20 分)