标题:Let the Balloon Rise
取消只看楼主
pavilion4994
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2013-10-17
结帖率:100%
已结贴  问题点数:10 回复次数:3 
Let the Balloon Rise
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
我写的:

#include <stdio.h>
#include <string.h>
struct bal
{
    int x;
    char c[1000];
};
int main()
{
    while(1)
    {
    int n,i,j;
    char s[1000];
    struct bal col[1111]={0};
    scanf("%d",&n);
    if(n==0)
        return 0;
    for(i=0;i<n;i++)
        scanf("%s",col[i].c);
    strcpy(s,col[0].c);
    for(i=0;i<n;i++)
    for(j=i+1;j<n;j++)
    {
        if(strcmp(col[i].c,col[j].c)==0)
            col[i].x++;
    }
    for(i=0;i<n-1;i++)
        if(col[i].x<col[i+1].x)
           strcpy(s,col[i+1].c);
    printf("%s\n",s);
    }
}
感觉没什么错为何wrong answer
搜索更多相关主题的帖子: multiple contain popular problem secret 
2014-03-29 22:24
pavilion4994
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2013-10-17
得分:0 
回复 2楼 beyondyf
觉得这段代码就是找出重复次数最多的字符串(col[i].x存的是字符串重复次数,col[i].c是对应的字符串)然后将这个字符串拷贝到s中,这样比较下来,s中存的就是重复次数最多的字符串,感觉应该没错,望指教
2014-03-30 11:06
pavilion4994
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2013-10-17
得分:0 
回复 2楼 beyondyf
再看了一下,好像确实有些问题,应该是把找最小的代码写错了,我再改改
2014-03-30 11:18
pavilion4994
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2013-10-17
得分:0 
手误,找最大
2014-03-30 11:27



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-429378-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018370 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved