PAT (Advanced Level) Practice 1120 Friend Numbers (20 分)
#include<cstdio>
#include<vector>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;
map<int, int> mp;
vector<int> ans;
int main()
{
int n; scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
char s[10];
scanf("%s", s);
int len = strlen(s), sum = 0;
for (int i = 0; i<len; i++)
sum += s[i] - '0';
mp[sum]++;
}
for (auto it : mp)
if (it.second > 0)
ans.push_back(it.first);
ans.resize(unique(ans.begin(), ans.end()) - ans.begin());
printf("%d\n", ans.size());
for (int i = 0; i < ans.size(); i++)
printf ("%d%c", ans[i], " \n"[i + 1 == ans.size()]);
return 0;
}
相關推薦
PAT (Advanced Level) Practice 1120 Friend Numbers (20 分)
#include<cstdio> #include<vector> #include<map> #include<cstring> #include<algorithm> using namespace std; map<
PAT (Advanced Level) Practice 1084 Broken Keyboard (20 分)
On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on sc
PAT (Advanced Level) Practice 1081 Rational Sum (20 分)
按照題意模擬即可 #include<cstdio> using namespace std; typedef long long ll; ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); } ll lca(ll a,
PAT (Advanced Level) Practice 1015 Reversible Primes (20 分)
A reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a re
PAT (Advanced Level) Practice 1112 Stucked Keyboard (20 分)
#include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int N=1e3+5; char s[N]; int in[N],vis[N];
PAT (Advanced Level) Practice 1108 Finding Average (20 分)
#include<cstdio> #include<algorithm> #include<cstring> using namespace std; char s[100]; int len;double x; int check() {
PAT (Advanced Level) Practice 1041 Be Unique (20 分)
Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a numbe
PAT (Advanced Level) Practice 1084 Broken Keyboard (20 分)
On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not
PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分)(C++)(甲級)
1042 Shuffling Machine (20 分) Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are se
PAT (Advanced Level) Practice 1073 Scientific Notation (20 分)(C++)(甲級)
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The not
PAT (Advanced Level) Practice 1114 Family Property (25 分)
程式設計題 1114 Family Property (25 分) This time, you are supposed to help us collect the data for family-owned property. Given each per
PAT (Advanced Level) Practice 1107 Social Clusters (30 分)
1107 Social Clusters (30 分) When register on a social network, you are always asked to specify your hobbies in order to find some
PAT (Advanced Level) Practice 1004 Counting Leaves (30 分)樹的層次遍歷
A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child. Input Specification: Each
PAT (Advanced Level) Practice 1107 Social Clusters (30 分)並查集
When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. A socia
PAT (Advanced Level) Practice 1030 Travel Plan (30 分)單源最短路變式
A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a progra
PAT (Advanced Level) Practice 1126 Eulerian Path (25 分)
In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similarly, an Eulerian circuit is an Eulerian path which
PAT (Advanced Level) Practice 1134 Vertex Cover (25 分) set
1134 Vertex Cover (25 分) A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at least one vertex of the s
PAT (Advanced Level) Practice 1138 Postorder Traversal (25 分) 樹的重構
Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and inorder traversal sequences, you are supposed to out
PAT (Advanced Level) Practice 1085 Perfect Sequence (25 分)
子序列而非連續子序列,雙指標,列舉最大值,然後l指標不斷往左移 #include<cstdio> #include<algorithm> using namespace std; const int N=1e5+5; int a[N]; int main
PAT (Advanced Level) Practice 1083 List Grades (25 分)
#include<cstdio> #include<algorithm> #include<vector> using namespace std; const int N=1e3+5; struct People { char name[