Бендер-парламентер
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <cstdio>
#include <cctype>
#include <vector>
using namespace std;
typedef map<string,int> map1;
typedef map1::value_type mval1;
typedef const mval1 *pval1;
struct word_less: public binary_function<pval1, pval1, bool> {
bool operator()(const pval1 v1, const pval1 v2)
{ if(v1->second<v2->second) return false;
if(v1->second>v2->second) return true;
if(v1->first.length()>v2->first.length()) return true;
if(v1->first.length()<v2->first.length()) return false;
return v1->first<v2->first;
}
};
struct copy_val: public unary_function<mval1,pval1> {
pval1 operator()(const mval1 &v1)
{ return &v1;
}
};
vector<pval1> words;
map1 m1;
int main()
{ int i,ch;
string s;
while((ch=getchar())!=EOF)
{ if(isalpha(ch))
s+=tolower(ch);
else
{ if(s.length()>0)
++m1[s];
s.clear();
}
}
transform(m1.begin(),m1.end(),back_inserter(words),copy_val());
partial_sort(words.begin(),words.begin()+10,words.end(),word_less());
for(i=0;i<10;i++)
printf("%s\n",words[i]->first.c_str());
return 0;
}