航电1004题

u013163178 2015-04-04 04:37:10
http://acm.hdu.edu.cn/showproblem.php?pid=1004
这是我的代码,总是不能通过,可是我觉得我的格式和答案都没有错啊。
#include <map>
#include <iostream>
#include <string>
using namespace std;

string foo(int n)
{
map<string , size_t> color_count;
string color;
string s;
for(int i = 0 ;i < n ;++i)
{
cin >> color ;
//在map中查找color,找到则将他出现的次数家一,没有找到则插入他,出现次数为一
++color_count[color];
}

size_t sum = 0;
for(const auto &c : color_count)
{
if(c.second > sum)
s = c.first;
}

return s;
}
int main()
{

int n;
string color;
while(cin >> n && n != 0)
{
color = foo(n);
cout << color << endl;
}

return 0;
}
...全文
162 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

65,185

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧