杭电1004题
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//使用结构体实现
typedef struct
{
string color;
int time;
}balloon;
vector<balloon> balloons;
void popular_color();
void is_in(string color);
void big();
int main()
{
int n;
string color;
while(cin>>n)
{
balloons.clear();
if(n==0)
return 0;
else
{
for(int i=0;i<n;i++)
{
cin>>color;
is_in(color);
}
popular_color();
}
}
return 0;
}
//判断输入的气球是否在向量中,如果在则相应的次数加1,否则将其加入到向量组中
void is_in(string color)
{
bool flag = false;
for(vector<balloon>::iterator itr=balloons.begin ();itr!=balloons.end ();itr++)
{
if(color == (*itr).color )
{
(*itr).time ++;
flag = true;
break;
}
}
if(!flag)
{
balloon balloon_color;
balloon_color.color = color;
balloon_color.time = 1;
balloons.push_back (balloon_color);
}
}
void popular_color()
{
int max = 1;
for(vector<balloon>::iterator itr3=balloons.begin ();itr3!=balloons.end ();itr3++)
{
if((*itr3).time > max)
{
max =(*itr3).time ;
}
}
for(vector<balloon>::iterator itr1=balloons.begin ();itr1!=balloons.end ();itr1++)
{
if((*itr1).time == max)
{
cout<<(*itr1).color <<endl;
break;
}
}
}