I've submitted the problem several times but getting wrong answer.
My current version reads till EOF. Previously I've tried with getting only N lines.
My code works with the inputs in this forum. Please help..
Code: Select all
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef struct list_t{
unsigned long p;
char c;
char r[3];
bool operator<(const struct list_t &a){
return p > a.p;
}
}list_t;
static list_t cnt[92];
static const char lut[128] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 'A', 'B', 'C', 'D', 'E',
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
'Z', 0, 0, 0, 0, 0, 0, 'A', 'B', 'C',
'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', 0, 0, 0, 0, 0};
int main(){
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
for(int i = 'A'; i <= 'Z'; i++){
cnt[i].c = i;
}
unsigned int N;
scanf("%u\n", &N);
register char c;
while((c = getchar()) != EOF){
if(lut[c]){
cnt[lut[c]].p++;
}
}
sort(cnt + 'A', cnt + 'Z' + 1);
for(int i = 'A'; cnt[i].p; i++){
printf("%c %lu\n", cnt[i].c, cnt[i].p);
}
return 0;
}