朱色虫居
Pages
Home
Featured Posts
2006/10/14
499-What's The Frequency, Kenneth?
/*
"What's The Frequency, Kenneth?"
Level:2.0
Date:2006/10/13
技巧:利用陣列記錄A-Z,a-z 52個字母出現的頻率,再找最大的.
*/
#include
#include
main(){
int f[52]={0};
char input[100]={0};
int i=0,max=0;
while(gets(input)){
int max=0;
for(i=0;i<52;i++) f[i]=0; for(i=0;i
='A' && input[i]<='Z'){ f[input[i]-'A']++; if(max < f[input[i]-'A']) max = f[input[i]-'A']; } else if(input[i]>='a' && input[i]<='z'){ f[input[i]-'a'+26]++; if(max < f[input[i]-'a'+26]) max = f[input[i]-'a'+26]; } } for(i=0;i<52;i++){ if(f[i]== max){ if(i<26) printf("%c",i+'A'); else if(i>25)
printf("%c",i+'a'-26);
}
}
printf(" %d\n",max);
}
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment