Friday, April 24, 2015

UVa - 499 - What's The Frequency, Kenneth

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;

int main(){
    string text;
    int cnt[125], mx;
    while(getline(cin, text)){
        int sz = text.size();
        memset(cnt, 0, sizeof(cnt));
        for(int i = 0; i < sz; i++)
            if((text[i] >= 'a' && text[i] <= 'z') || (text[i] >= 'A' && text[i] <= 'Z'))cnt[text[i]]++;
        mx = cnt[0];
        for(int i = 0; i < 125; i++)if(mx < cnt[i])mx = cnt[i];
        for(int i = 0; i < 125; i++)if(mx == cnt[i])printf("%c", i);
        cout << " " << mx << endl;
    }
    return 0;
}

No comments:

Post a Comment