64,671
社区成员
发帖
与我相关
我的任务
分享
#include <set>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int most=0;
int main()
{
map<string,int> M;
set<string> S;
ifstream F("text.txt");
while(!F.eof() )
{
string str;
F >>str;
int n=++M[str];
if(n>most) most=n;
}
F.close();
for(map<string,int>::iterator it=M.begin();it!=M.end();++it)
if(most==(int)it->second)
S.insert(it->first);
cout <<"frequence:\t" <<most <<endl;
cout <<"words:";
for(set<string>::iterator it=S.begin();it!=S.end();++it)
cout <<'\t' <<*it;
cout <<endl;
return 0;
}