Friday, July 25, 2014

UVa - 10062 - Tell me the frequencies!

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

int main(){
    int cnt[128], space = 0;
    vector <int> faaltu;
    string sample;
    while(getline(cin, sample)){
        memset(cnt, 0, sizeof(cnt));
        int l = sample.size();
        for(int i = 0; i < l; i++)cnt[sample[i]]++;
        for(int i = 1; i <= 127; i++)if(cnt[i] != 0)faaltu.push_back(cnt[i]);
        int limit = faaltu.size(), mn = 1010, index;
        if(space == 1)cout << endl;
        for(int i = 1; i <= limit; i++){
            for(int j = 32; j <= 127; j++){
                if(mn >= cnt[j] && cnt[j] > 0){
                    mn = cnt[j], index = j;
                }
            }
            if(index == 92)mn /= 2;
            if(mn != 0)cout << index << " " << mn << endl;
            cnt[index] = 0, mn = 1010;
        }
        space = 1;
        faaltu.clear();
    }
    return 0;
}

No comments:

Post a Comment