| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1046 人关注过本帖
标题:杭电 ACM1004 题,我的答案第二次输入时输出的总是与第一题的数据有关,求解 ...
取消只看楼主 加入收藏
OKAITO
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-12-4
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
杭电 ACM1004 题,我的答案第二次输入时输出的总是与第一题的数据有关,求解答。
#include <stdio.h>
#include <string.h>
int main()
{
    char balloon[1001][15];
    int i,j,N,n,num[1001],max=0;
    while (scanf("%d",&N)!=EOF && N!=0)
    {
    for (i=0;i<N;i++)
        scanf("%s",balloon[i]);
    for (i=0;i<1001;i++)
        num[i]=0;
    for (i=0;i<N;i++)
        for (j=1;j<N;j++)
        {
            if (i>=j) continue;
            else if (strcmp(balloon[i],balloon[j])==0)
                num[i]++;
        }
    for (i=0;i<1001;i++)
    {
        if (num[i]>=max)
        {
            max=num[i];
            n=i;
        }
    }
    printf("%s\n",balloon[n]);
    }
    return 0;
}
搜索更多相关主题的帖子: continue balloon include 
2014-12-04 16:23
OKAITO
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-12-4
收藏
得分:0 
回复 2 楼 诸葛欧阳
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
2014-12-04 19:41
OKAITO
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-12-4
收藏
得分:0 
回复 2 楼 诸葛欧阳
先输入气球数量,然后输入颜色,输出颜色最多的那个
2014-12-04 19:42
OKAITO
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-12-4
收藏
得分:0 
回复 5 楼 巧若拙
懂了,谢谢!
2014-12-04 21:49
快速回复:杭电 ACM1004 题,我的答案第二次输入时输出的总是与第一题的数据有关 ...
数据加载中...
 
   



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

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