文章
43
粉丝
180
获赞
32
访问
200.6k
- #include <iostream>
- #include <map>
- #include <algorithm>
- using namespace std;
- const int N = 1010;
-
- char x;
- string s;
- map<string, int> h;
-
- struct node
- {
- string s;
- int cnt;
- }r[N];
-
- bool cmp(node a, node b)
- {
- return a.cnt > b.cnt;
- }
-
- int main()
- {
- int n = 1010;
- while (n -- )
- {
- scanf("%c", &x);
- if (x != ' ' && x != ',' && x != '.')
- {
- if (x >= 'A' && x <= 'Z') s += x - 'A' + 'a';
- else s += x;
- }
- else
- {
- h[s] ++;
- s.clear();
- }
- }
- int p = 0;
- for (auto& a : h) if (a.first != "") r[p].s = a.first, r[p ++ ].cnt = a.second;
- sort(r, r + p, cmp);
- for (int i = 0; i < p; i ++ ) cout << r[i].s << ":" << r[i].cnt << endl;
- return 0;
- }
登录后发布评论
暂无评论,来抢沙发