#include <iostream> #include <set> // set 集合中没有重复的元素 using namespace std; int cmp(int t) { int sum = 0; while (t != 0) { sum += t % 10; t /= 10; } return sum; } int main() { int n, x; set <int> st; cin >> n; while (n--) { cin >> x; st.insert(cmp(x)); } cout << st.size() << endl; for (auto it = st.begin(); it != st.end(); it++) { // auto自动推断变量类型 if (it != st.begin()) { cout << ‘ ‘; } cout << *it; } cout << endl; return 0; }
原文地址:https://www.cnblogs.com/Hk456/p/10788375.html
时间: 2024-09-29 20:07:53