64,637
社区成员
发帖
与我相关
我的任务
分享
#pragma warning(disable: 4786)
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
map <string ,int> m;
map <string, int> n_m;
string s;
while(cin >> s)
{
++m[s];
cin.sync();
cin.clear();
}
for(map <string, int>::iterator it = m.begin(); it != m.end(); )
{
if(it-> second > (++it)-> second)
{
if(it == m.end())
break;
n_m.insert(pair <string, int> (it-> first, it-> second));
++it;
n_m.insert(pair <string, int> (it-> first, it-> second));
}
else
{
--it;
n_m.insert(pair <string, int> (it-> first, it-> second));
++it;
n_m.insert(pair <string, int> (it-> first, it-> second));
}
}
for(map <string, int>::iterator n_it = n_m.begin(); n_it != n_m.end(); ++n_it)
{
cout << n_it-> first << '\t' << n_it-> second << '\n';
}
return 0;
}