Skip to content

Commit 9d7ad67

Browse files
committed
Solve problem 1251 - Tell me the Frequencies! from URI
1 parent f7747c3 commit 9d7ad67

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}

URI/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
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)

0 commit comments

Comments
 (0)