-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1251.cpp
More file actions
41 lines (36 loc) · 883 Bytes
/
1251.cpp
File metadata and controls
41 lines (36 loc) · 883 Bytes
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
#include <bits/stdc++.h>
#define MAX 1001
typedef struct {
char letter;
int rep;
}vet;
std::vector<vet> count_duplicates(char str[])
{
std::unordered_map<char, int> mp;
std::vector<vet> ans;
for(int i=0; str[i]!='\0'; i++)
mp[str[i]]++;
for(auto& i : mp)
ans.push_back({i.first, i.second});
return ans;
}
int main(int argc, char *argv[])
{
char str[MAX];
int print=0;
while(scanf(" %1000[^\n]", str) != EOF)
{
if(print != 0)
printf("\n");
std::vector<vet> v = count_duplicates(str);
std::sort(v.begin(), v.end(), [](vet v1, vet v2) -> bool {
if(v1.rep != v2.rep)
return v1.rep < v2.rep;
return v1.letter > v2.letter;
});
for(auto& i : v)
printf("%d %d\n", i.letter, i.rep);
print=1;
}
return 0;
}