Saturday, December 31, 2016

Toph - Word Count

#include
using namespace std;


char buff[101];
int main()
{
    map < string , int > tree ;
    while( gets(buff) ) {
        string str = buff;
        stringstream sin(str);
        string token;
        while(sin >> token){
            tree[token]++;
        }
    }
    string ans;
    int i = 0 , k = 0;
    for(map :: iterator it = tree.begin() ; it  != tree.end()  ; it++ , i++ ){
        if((it->second) > k and i != 0){
            k = it->second;
            ans = it->first;
        }
        if (i == 0) k = it->second , ans = it->first;
    }
cout << ans << endl;
    return 0;
}

No comments: