hdu1004.cpp
来自「HDu1000-1005,杭州电子科技大学ACM题」· C++ 代码 · 共 44 行
CPP
44 行
//*************************************************************************
//*程 序 名:HDu1004.CPP *
//*作 者:FLYLIKEABIRD(LIANG YI MING) *
//*编制时间:2008.09.08 *
//*主要功能: Let the Balloon Rise *
//*************************************************************************
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
int nCount=0;
string strTmp;
while(cin>>nCount&&nCount!=0)
{
map<string,int> mapColor;//用map容器非常方便
for(int i=0;i<nCount;++i)
{
cin>>strTmp;
mapColor[strTmp]++;
}
map<string, int>::iterator iter;
int max = -1;
for(iter = mapColor.begin(); iter != mapColor.end(); iter++)
{//第一次遍历标记最大次数所在位置
if(iter->second>max)
{
max = iter->second;
}
}
for(iter = mapColor.begin(); iter != mapColor.end(); iter++)
{//第二次遍历找到标记的位置
if(iter->second==max)
{
cout<<iter->first<<endl;
}
}
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?