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