| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 524 人关注过本帖
标题:Let the Balloon Rise
只看楼主 加入收藏
pavilion4994
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2013-10-17
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:4 
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
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:10 
程序代码:
    for(i=0;i<n-1;i++)
        if(col[i].x<col[i+1].x)
           strcpy(s,col[i+1].c);

这段代码逻辑是错的。

不过即使解决了这个问题,你之前的代码效率太低,恐怕也会 time limit exceeded。

另外,你再阅读一下题目看看各量的定义域,不要做无谓的浪费。

重剑无锋,大巧不工
2014-03-30 08:25
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
快速回复:Let the Balloon Rise
数据加载中...
 
   



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

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