标签:pre c++ ber insert main include 数位 mes ==
如果两个数的数位和一样那么这两个数就是友好数,称数位和为友好ID,现在要找出给定的序列中有几个不同的友好ID
set
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <string.h>
#include <set>
using namespace std;
int add(int x) {
int sum = 0;
while(x) {
int t = x % 10;
x /= 10;
sum += t;
}
return sum;
}
int main() {
int n, t;
cin >> n;
set<int> s;
for(int i = 0; i < n; i++) {
cin >> t;
int digit_sum = add(t);
s.insert(digit_sum);
}
cout << s.size() << endl;
if(s.size() != 0) {
for(auto it = s.begin(); it != s.end(); it++) {
if(it == s.begin())
cout << *(it);
else
cout << " " << *(it);
}
}
return 0;
}
PAT(Advanced Level)A1120. Friend Numbers
标签:pre c++ ber insert main include 数位 mes ==
原文地址:https://www.cnblogs.com/MartinLwx/p/14530341.html