#include<iostream> #include<set> usingnamespace std; int N; int num; set<int>ans; intcal(int num){ int a = 0; while (num != 0) { a += num % 10; num = num / 10; } return a; } intmain(){ cin >> N; for (int i = 0; i < N; i++) { cin >> num; ans.insert(cal(num)); } cout << ans.size() << endl; int i = 0; for (auto it = ans.begin(); it != ans.end();it++) { cout << *it; i++; if (i != ans.size()) cout << " "; } }
#include<iostream> #include<vector> #include<map> #include<string> usingnamespace std; int G[202][202]; bool flag[202]; intmain(){ int N, M; cin >> N >> M; int a, b; for (int i = 0; i < M; i++) { cin >> a >> b; G[a][b] = 1; G[b][a] = 1; } int K, num; cin >> K; for (int i = 0; i < K; i++) { bool cycle = true; cin >> num; if (num != N + 1) { cycle = false; string s; getline(cin, s); } else { fill(flag, flag + 202, false); int start, p; cin >> start; int pre = start; for (int i = 1; i < num; i++) { cin >> p; if (!G[pre][p]||flag[p]) { cycle = false; //break; } pre = p; flag[p] = true; } if (p != start) cycle = false; } if (!cycle) cout << "NO\n"; else cout << "YES\n"; } }