Friday, April 24, 2015

UVa - 10008 - What's Cryptanalysis

#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main(){
    int i, n, j, cnt[30], ans[30];
    string input;
    char c;
    while(cin >> n){
        getchar();
        memset(cnt, 0, sizeof(cnt));
        memset(ans, 0, sizeof(ans));
        for(i = 0; i < n; i++){
            getline(cin, input);
            for(j = 0; input[j]; j++){
                if(input[j] >= 97 && input[j] <= 122){
                    cnt[input[j]-97]++;
                    ans[input[j]-97]++;
                }
                else if(input[j] >= 65 && input[j] <= 90){
                    cnt[input[j]-65]++;
                    ans[input[j]-65]++;
                }

            }
        }
        sort(ans, ans+26);
        for(i = 25; i >= 0; i--){
            if(ans[i] != 0){
                for(j = 0; j < 26; j++){
                    if(ans[i] == cnt[j]){
                        printf("%c %d\n", (j+65), cnt[j]);
                        cnt[j] = 0;
                    }
                }
            }


        }
    }
    return 0;
}

No comments:

Post a Comment