These code is for the problem "Let the balloons Fly" in ACM 1004 which need deal with string.
It is a little difficult in some content so that I rewrite it here to let more confused students have access to it.
It can be accepted by handing it in G++.
#include<iostream>
#include<cstring>
using namespace std;
string judge(int len)
{
int i,j,n=0;
string color[1000],colo[1000];
int co[1000]={0};
for(i=0;i<len;i++)
{
cin>>color[i];
}
for(i=0;i<len;i++)
{
colo[i]=color[i];
for(j=0;j<len;j++)
{
if(colo[i]==color[j])
co[i]++;
}
}
int num;
num=co[0];n=0;
for(i=1;i<len;i++)
{
if(num<co[i])
{n=i;
num=co[i];
}
}
return color[n];
}
int main()
{
int n;
int i=0;
string yanse[1000];
cin>>n;
while(n!=0)
{
yanse[i]=judge(n);
i++;
cin>>n;
}
for(n=0;n<i;n++)
cout<<yanse[n]<<endl;
return 0;
}