求助-C语言编程-杭电ACM1004
编程吧
全部回复
仅看楼主
level 6
冰中结 楼主
怎么搞都过不了,又查不出毛病,求源码和注释
2012年04月21日 06点04分 1
level 6
冰中结 楼主
具体题目如下:
Problem Description:
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.
Input:
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.
A test case with N = 0 terminates the input and this test case is not to be processed.
Output:
For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.
Sample Input:
5
green
red
blue
red
red
3
pink
orange
pink
0
Sample Output:
red
pink
Author:
WU, Jiazhi
Source:
ZJCPC2004
Recommend:
JGShining
2012年04月21日 06点04分 2
level 6
简单模拟
代码如下:
#include<stdio.h>
#include<string.h>
char a[1010][20];
int main()
{
int n,i,k,j,max;
char b[20];
int c[1010];
memset(a,0,sizeof(a));
while(1)
{
scanf("%d",&n);
if(n==0)
break;
memset(c,0,sizeof(c));
k=0;
for(i=1;i<=n;i++)
{
memset(b,0,sizeof(b));
scanf("%s",b);
for(j=1;j<k;j++)
{
if(strcmp(b,a[j])==0)
{
c[j]++;
break;
}
}
if(j>=k)
{
k++;
c[k]++;
strcpy(a[k],b);
}
}
max=0;
for(i=1;i<=k;i++)
{
if(c[i]>=max)
{
max=c[i];
j=i;
}
}
printf("%s\n",a[j]);
}
return 0;
}

2012年04月21日 10点04分 3
level 1
去百度NOIP吧…模拟题我们初|高中生可以轻松应付…
2012年04月21日 12点04分 4
level 6
冰中结 楼主
[瀑布汗~]
2012年04月21日 12点04分 5
level 6
冰中结 楼主
[拜]
2012年04月21日 12点04分 6
1