// UVa 10062 - Tell me the frequencies! #include <stdio.h> #include <map> #include <vector> #include <algorithm> #include <string> #include <iostream> using namespace std; #define ch unsigned char struct pa { char c; int f; }; bool operator <(pa a, pa b) { return a.f < b.f || (a.f == b.f && a.c > b.c); } int main() { string s; int t = 0; while (getline(cin, s)) { t++; map<ch, int> m; for (int i = 0; i < s.length(); i++) m[s[i]]++; vector<pa> v; for (ch c = 32; c <= 128; c++) if (m[c] != 0) { pa p = { c, m[c] }; v.push_back(p); } sort(v.begin(), v.end()); if (t > 1) cout << endl; for (int i = 0; i < v.size(); i++) printf("%d %d\n", v[i].c, v[i].f); } return 0; }
Sunday, June 14, 2015
UVa 10062 - Tell me the frequencies!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment