File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed
Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ #include < string>
3+ #include < vector>
4+ #include < algorithm>
5+
6+ using namespace std ;
7+
8+ int arr[129 ] = {0 };
9+ vector<pair<int , int > > res;
10+
11+
12+ int main () {
13+ string s;
14+ getline (cin, s);
15+
16+ while (true ) {
17+ for (int i = 0 ; i < 129 ; i++) arr[i] = 0 ;
18+ res.clear ();
19+
20+ for (int i = 0 , len = s.length (); i < len; i++)
21+ arr[int (s[i])]++;
22+
23+ for (int i = 0 ; i < 129 ; i++) {
24+ int max = 0 ;
25+ for (int j = 0 ; j < 129 ; j++)
26+ if (arr[j] > arr[max])
27+ max = j;
28+ res.push_back (make_pair (max, arr[max]));
29+ arr[max] = -1 ;
30+ }
31+
32+ reverse (res.begin (), res.end ());
33+
34+ for (int i = 0 ; i < 129 ; i++)
35+ if (res[i].second != 0 ) {
36+ cout << res[i].first << ' ' << res[i].second ;
37+ if (i + 1 != 129 )
38+ cout << endl;
39+ }
40+
41+ if (getline (cin, s))
42+ cout << endl << endl;
43+ else {
44+ cout << endl;
45+ break ;
46+ }
47+ }
48+
49+ return 0 ;
50+ }
Original file line number Diff line number Diff line change 2727- [ 1244 - Sort by Length] ( https://www.urionlinejudge.com.br/judge/en/problems/view/1244 )
2828- [ 1245 - Lost Boots] ( https://www.urionlinejudge.com.br/judge/en/problems/view/1245 )
2929- [ 1249 - Rot13] ( https://www.urionlinejudge.com.br/judge/en/problems/view/1249 )
30+ - [ 1251 - Tell me the Frequencies!] ( https://www.urionlinejudge.com.br/judge/en/problems/view/1251 )
3031- [ 1256 - Hash Tables] ( https://www.urionlinejudge.com.br/judge/en/problems/view/1256 )
3132- [ 1257 - Array Hash] ( https://www.urionlinejudge.com.br/judge/en/problems/view/1257 )
3233- [ 1258 - T-Shirts] ( https://www.urionlinejudge.com.br/judge/en/problems/view/1258 )
You can’t perform that action at this time.
0 commit comments