-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy path10008 - What's Cryptanalysis?.cpp
49 lines (47 loc) · 1.08 KB
/
10008 - What's Cryptanalysis?.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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
int cmp(int a,int b)
{
if(a>b)return 1;
return 0;
}
int main()
{
int t,cnt[250],k,i,len,m[250],use[30];
char ch,msg[100];
while(scanf("%d",&t)==1)
{
memset(cnt,0,sizeof(cnt));
getchar();
while(t--)
{
gets(msg);
len=strlen(msg);
for(k=0; k<len; k++)
{
if(msg[k] >= 'a' && msg[k] <= 'z' ) cnt[ msg[k] - 97 ]++;
else if(msg[k] >= 'A' && msg[k] <= 'Z' ) cnt[ msg[k] - 65 ]++;
}
}
memset(use,0,sizeof(use));
for(i=0; i<26; i++)m[ i ]=cnt[i];
sort(cnt,cnt+26,cmp);
for(i=0; i<26; i++)
{
if(cnt[i])
{
for(k=0; k<26; k++)
if(m[k]==cnt[i] && !use[k])
{
use[k]=1;
break;
}
printf("%c %d\n",k+65,cnt[i]);
}
}
}
return 0;
}