感觉结果没毛病啊然鹅T _ T
要求:如果数目相同,按字母序全部输出,每种颜色一行
A test case with N = 0 terminates the input and this test case is not to be processed.
Sample Input:
5
green
red
blue
red
red
3
pink
orange
pink
0
Output:
red
pink
下面是我的代码和运行结果:
#include<string.h>
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
if(n==0)
break;
char a[1000][16];
int b[1000]={0};
char c[16];
int i,j;
getchar();
for(i=1;i<=n;i++)
{
gets(a[i]);
}
for(i=1;i<=n-1;i++)
{
for(j=i+1;j<=n;j++)
{
if(strcmp(a[j],a[i])<0)
{
strcpy(c,a[i]);
strcpy(a[i],a[j]);
strcpy(a[j],c);
}
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
if(strcmp(a[i],a[j])==0)
b[i]++;
}
int max=1,m=1;
for(i=1;i<=n;i++)
{
if(b[i]>max)
{
m=i;
max=b[i];
}
}
if(max==1)
{
for(i=1;i<=n;i++)
cout<<a[i]<<endl;
}
else
{
cout<<a[m]<<endl;
for(i=m+1;i<=n;i++)
{
if((b[i]==max)&&(strcmp(a[i],a[m])!=0))
cout<<a[i]<<endl;
m=i;
}
}
}
return 0;
}