航电1004题

「已注销」 「已注销」 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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;
}
...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
「已注销」
C++ 语言 65,214 成员 250,514 内容