PersonalCorpus 版 (精华区)
Your C++ program has solved Ok the problem 10008 (What\'s
Cryptanalysis?)
in 0.000 seconds with low memory spent.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <math.h>
#include <ctype.h>
void main()
{
#ifndef ONLINE_JUDGE
freopen("c:\\uva\\input10008.txt","r",stdin);
freopen("c:\\uva\\output10008.txt","w",stdout);
#endif
char a[26];
int sum[26];
int i,j,k,n;
char ch;
scanf("%d\n",&n);
memset(sum,0,sizeof(sum));
for (i=0;i<26;i++) a[i]=i+65;
while (n>0) {
ch=getchar();
if ((ch=='\n')||(ch==EOF)) n--;
if (isalpha(ch))
if ((ch>='a')&&(ch<='z')) sum[ch-'a']++; else
sum[ch-'A']++;
}
for (i=0;i<25;i++) for(j=i+1;j<26;j++)
if ((sum[i]<sum[j])||((sum[i]==sum[j])&&(a[i]>a[j]))) {
k=sum[i]; sum[i]=sum[j]; sum[j]=k;
k=a[i];a[i]=a[j];a[j]=k;
}
for (i=0;i<26;i++) {
if (sum[i]==0) break;
printf("%c %d\n",a[i],sum[i]);
}
}
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:5.909毫秒