PAT 甲级 1120 Friend Numbers (20) set的应用

/*
  PAT 甲级 1120 set
*/

#include 
#include 
using namespace std;
int id(int num){
    int sum = 0;
    while(num){
     sum = sum + num%10;
     num = num /10;
    }
    return sum;
}
int main() {
    int n;
    set s;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        int v;
        scanf("%d", &v);
        s.insert(id(v));
    }
    cout << s.size() << endl;
    for(auto it = s.begin(); it != s.end(); it++){
        if(it != s.begin()) printf(" ");
        printf("%d", *it);
    }
    return 0;
}

你可能感兴趣的:(PAT 甲级 1120 Friend Numbers (20) set的应用)