Created
September 24, 2012 15:04
-
-
Save Yi-Tseng/3776423 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <ctype.h> | |
struct node{ | |
int cn; | |
char c; | |
}; | |
typedef struct node Node; | |
int main(int argc, const char * argv[]) | |
{ | |
Node cc[26]; | |
char a; | |
int c; | |
// init nodes | |
for(c=0;c<26;c++){ | |
cc[c].c = c+'A'; | |
cc[c].cn = 0; | |
} | |
while(scanf("%c",&a)!=EOF){ | |
if(isalpha(a)){ | |
a = toupper(a); | |
cc[a-'A'].cn++; | |
} | |
} | |
int e,f; | |
// bobble sort | |
for(e=0;e<26;e++){ | |
for(f=0;f<26-1;f++){ | |
if(cc[f].cn < cc[f+1].cn){ | |
Node tmp = cc[f]; | |
cc[f] = cc[f+1]; | |
cc[f+1] = tmp; | |
} | |
} | |
} | |
for(c=0;c<26;c++){ | |
if(cc[c].cn!=0){ | |
printf("%c %d\n",cc[c].c,cc[c].cn); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment