64,687
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <map>
#include <string>
using namespace std;
void main ()
{
string input;
typedef map<string, int> StrIntMap;
StrIntMap ma;
long i = 0;
while (cin>>input && input != "fuck")
{
ma[input] = i;
}
map<string, int>::iterator pos1;
map<string, int>::iterator pos2;
for (pos1 = ma.begin(); pos1 != ma.end(); pos1++)
{
for (pos2 = ma.begin(); pos2 != ma.end(); pos2++)
{
if (pos1->first == pos2->first) ++i;
}
ma[pos1->first] = i;
i = 0;
}
for (pos1 = ma.begin(); pos1 != ma.end(); pos1++)
{
cout<<pos1->first<<" "<<pos1->second<<"\n";
}
}
#include <iostream>
#include <map>
#include <string>
using namespace std;
void main ()
{
string input;
typedef map<string, int> StrIntMap;
StrIntMap ma;
long i = 0;
while (cin>>input && input != "fuck")
{
ma[input]++;
}
map<string, int>::iterator pos1;
for (pos1 = ma.begin(); pos1 != ma.end(); pos1++)
{
cout<<pos1->first<<" "<<pos1->second<<"\n";
}
}
#include <iostream>
#include <map>
#include <string>
using namespace std;
void main ()
{
string input;
map<string, int> ma;
while (cin>>input && input != "fuck")
{
ma[input]++;
}
map<string, int>::reverse_iterator it=ma.rbegin();
cout<<(*it).first<<" "<<(*it).second<<endl;
}