Created
October 30, 2015 05:56
-
-
Save wildskyf/8681f8fd93e7d35f0d5e to your computer and use it in GitHub Desktop.
ACM 10008
This file contains hidden or 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> | |
#include <algorithm> | |
#include <vector> | |
class Alpha | |
{ | |
public: | |
char c; | |
int value; | |
}; | |
bool compare (Alpha i,Alpha j) | |
{ | |
return (i.value>j.value); | |
} | |
int main() | |
{ | |
int numC = 0; | |
while( scanf("%d", &numC) != EOF ) { | |
getchar(); | |
Alpha alpha[26] = {0}; | |
for(int i = 0 ; i < numC ; ++i) | |
while(1) { | |
char c = getchar(); | |
if(c == '\n') break; | |
if (toupper(c) >= 'A' && (toupper(c)<= 'Z')) { | |
alpha[(toupper(c) - 'A')].c = toupper(c); | |
alpha[(toupper(c) - 'A')].value++; | |
} | |
} | |
std::vector<Alpha> a; | |
a.assign(alpha,alpha+26); | |
std::stable_sort (a.begin(), a.end(), compare); | |
for(int i = 0 ; i < 26 ; ++i) | |
if(a[i].value > 0) { | |
printf("%c %d\n", a[i].c, a[i].value); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment