-
Notifications
You must be signed in to change notification settings - Fork 0
/
difficult.cpp
59 lines (48 loc) · 975 Bytes
/
difficult.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
#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <string>
#define ll long long
using namespace std;
struct cmp
{
bool operator() (const pair<char, ll>& a, const pair<char, ll>& b)
{
if( a.second == b.second){
return a.first > b.first;
}
return a.second < b.second;
}
};
map <char,ll> frequency;
set < pair<char,ll> , cmp > result;
void initialize(){
for(char i='a';i<='z';i++)
frequency[i] = 0;
}
void getFrequency(string input){
for(int i=0;i<input.size();i++){
frequency[input[i]] += 1 ;
}
map < char,ll>::iterator it;
for(it = frequency.begin();it!=frequency.end();it++){
result.insert(make_pair(it->first,it->second));
}
}
int main(void){
int T;
cin >> T;
while(T--){
string input;
cin >> input;
initialize();
result.clear();
getFrequency(input);
set < pair<char,ll> , cmp >::iterator it;
for(it=result.begin();it!=result.end();++it){
cout << it->first << " ";
}
cout << endl;
}
}