Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color
and find the result.
This year, they decide to leave this lovely job to you.
This year, they decide to leave this lovely job to you.
A test case with N = 0 terminates the input and this test case is not to be processed.
5 green red blue red red 3 pink orange pink 0
red pink
#include<iostream>
#include<cstdio>#include<string>
#include<vector>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n)&&n)
{
string s;
vector<int>times;
vector<string>color;
for(int i=0;i<n;i++)
{
cin>>s;
color.push_back(s);
}
for(int j=0;j<color.size();j++)
times.push_back(1);
for(int i=0;i<color.size();i++)
{
for(int j=i+1;j<color.size();j++)
{
if(color[i]==color[j])
{
times[j]++;
times[i]++;
}
}
}
int max=0;
string Smost;
for(int i=0;i<times.size();i++)
{
if(times[i]>max)
{
max=times[i];
Smost=color[i];
}
}
cout<<Smost<<endl;
}
return 0;
}
本文介绍了一个简单的程序设计问题,即统计比赛中各颜色气球的数量来找出最受欢迎的问题。输入包括多个测试用例,每个用例首先给出气球总数,随后列出每只气球的颜色。输出则是出现次数最多的气球颜色。
1016

被折叠的 条评论
为什么被折叠?



