forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path10062.cpp
More file actions
53 lines (49 loc) · 705 Bytes
/
10062.cpp
File metadata and controls
53 lines (49 loc) · 705 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
42
43
44
45
46
47
48
49
50
51
52
53
#include <bits/stdc++.h>
using namespace std;
char str[1005];
int sum[129];
typedef struct
{
int ascii, cnt;
} kind;
kind data[128];
int cmp(kind a, kind b)
{
if (a.cnt != b.cnt)
{
return a.cnt < b.cnt;
}
return a.ascii > b.ascii;
}
int main()
{
int total = 0;
while (gets(str))
{
if (total++)
{
printf("\n");
}
memset(sum, 0, sizeof(sum));
for (int i = 0; str[i]; ++i)
{
sum[str[i]]++;
}
int cnt = 0;
for (int i = 32; i < 128; ++i)
{
if (sum[i])
{
data[cnt].ascii = i;
data[cnt].cnt = sum[i];
cnt++;
}
}
sort(data, data + cnt, cmp);
for (int i = 0; i < cnt; ++i)
{
printf("%d %d\n", data[i].ascii, data[i].cnt);
}
}
return 0;
}