-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10062.cpp
66 lines (58 loc) · 1.02 KB
/
10062.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
10062 - Tell me the frequencies!
*/
#include<bits/stdc++.h>
using namespace std;
bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
if(i.second==j.second)return i.first>j.first;
else
{
return i.second < j.second;
}
}
int main()
{
string str;
int t=0;
while(getline(cin, str))
{
t++;
int ar[130]= {0};
int len = str.length();
vector< pair<int,int> >v;
for(int i=0; i<len; i++)
{
int d = (int)str[i];
ar[d]++;
}
for(int i=0; i<130; i++)
{
if(ar[i]!=0)
{
v.push_back(make_pair(i,ar[i]));
}
}
sort(v.begin(),v.end(),compare);
if(t>1)cout<<endl;
for(int i=0; i<v.size(); i++)
{
cout<<v.at(i).first<<" ";
cout<<v[i].second<<endl;
}
v.erase(v.begin(), v.end());
}
return 0;
}
/*
Sample Input
AAABBC
122333
Sample Output
67 1
66 2
65 3
49 1
50 2
51 3
*/