Skip to content

Instantly share code, notes, and snippets.

@wildskyf
Created October 30, 2015 05:56
ACM 10008
#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