Created
October 29, 2014 10:45
-
-
Save amoshyc/15f57e5c6da852300e2d to your computer and use it in GitHub Desktop.
uva10008.c
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 <stdlib.h> | |
#include <string.h> | |
#include <ctype.h> | |
struct Node_ | |
{ | |
char c; | |
int cnt; | |
}; | |
typedef struct Node_ Node; | |
int compare_node(const void * a, const void * b) | |
{ | |
Node* na = (Node*) a; | |
Node* nb = (Node*) b; | |
if (na->cnt > nb->cnt) | |
return -1; | |
if (na->cnt < nb->cnt) | |
return +1; | |
if (na->c < nb->c) | |
return -1; | |
if (na->c > nb->c) | |
return +1; | |
return 0; | |
} | |
int main() { | |
int N; | |
scanf("%d\n", &N); | |
Node data[26]; | |
int i; | |
for (i=0; i<26; i++) { | |
data[i].c = (char) (i + 'A'); | |
data[i].cnt = 0; | |
} | |
while (N--) { | |
char inp[1024]; | |
fgets(inp, 1024, stdin); | |
int len = strlen(inp); | |
if (inp[len-1] == '\n') { | |
inp[len-1] = '\0'; | |
len--; | |
} | |
for (i=0; i<len; i++) | |
if (islower(inp[i])) | |
inp[i] = inp[i] - 'a' + 'A'; | |
for (i=0; i<len; i++) | |
if (isalpha(inp[i])) | |
data[(int) (inp[i] - 'A')].cnt++; | |
} | |
qsort(data, 26, sizeof(Node), compare_node); | |
for (i=0; i<26; i++) | |
if (data[i].cnt != 0) | |
printf("%c %d\n", data[i].c, data[i].cnt); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment