0029 - English Sentence

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
using namespace std;

map<string,int> data;

bool compare(const pair<string,int> T1, const pair<string,int> T2)	{
	return T1.second < T2.second;
}

string Slove(string word, string max_length)	{
	if (max_length.size() < word.size() )	max_length=word;
	++data[word];
	return max_length;
}

int main(void)	{
	string word, max_length="";

	while (cin >> word)
		max_length=Slove(word,max_length);
	pair<string,int> max_mode=*max_element(data.begin(),data.end(),compare);
	cout << max_mode.first << " " << max_length << endl;
	return 0;
}

文字数が多い文字列は逐次処理していく。
最頻出文字列はmapで文字と頻出数を取って、
maxelementを用いてsecondの値(頻出数)の大きいのを取ってくる。