| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 603 人关注过本帖
标题:(ACM题)结果正确,但反馈wrong answer。怎么回事?
只看楼主 加入收藏
赤云
Rank: 2
等 级:论坛游民
帖 子:82
专家分:35
注 册:2014-12-29
结帖率:64.71%
收藏
 问题点数:0 回复次数:1 
(ACM题)结果正确,但反馈wrong answer。怎么回事?
请大神指教,拜谢!
试题:
    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"malloc.h"
int fun(char *p1,char *p2);
struct A{
    char a[15];
    struct A *next;
};
struct A *create(int n){
    struct A *p,*tail,*head;
    int i;
    if(n==1){p=(struct A*)malloc(15);
             scanf("%s",p->a);
             p->next=NULL;
             return p;
    }
    else for(i=1;i<=n;i++){
        p=(struct A*)malloc(15);
        scanf("%s",p->a);
        if(i==1){head=p;  tail=p;}
        else {tail->next=p; tail=p; p->next=NULL;}
    }     
    return head;
}
int main(){
    int n,max=0,m=0,n1;
    struct A *p,*p1;
    char *px;
    do{
       scanf("%d",&n);
       if(n==0) break;
       p1=p=create(n);
       n1=n;  
       px=p->a;
       do{
          while(n--){
             if(fun(p->a,p1->a)) m++;  
             if(p->next!=NULL) p=p->next;
             else {p=p->next;break;}
          }
          n=n1; if(m>max) {px=p1->a;max=m;}m=0; p=p1; p1=p1->next;
       }while(p1->next!=NULL);
       printf("\n");
       puts(px);
    }while(n!=0);
    return 0;
}
int fun(char *p1,char *p2){
    while(*p1==*p2){
        if(*p1=='\0')break;
        p1++;
        p2++;
    }
    if(*p1=='\0') return 1;
    else return 0;
}
  
搜索更多相关主题的帖子: popular multiple decide secret problem 
2015-04-04 09:38
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
参见你的另一贴https://bbs.bccn.net/thread-443526-1-1.html
程序代码:
#include <stdio.h>
#include <string.h>

int main()
{
    char s[1024][16], t[16];
    int c[1024], n, sn, i, j;

    for(; scanf("%d", &n), n; puts(s[n]))
    {
        for(sn = i = 0; i < n && scanf("%s", t); i++)
        {
            for(j = 0; j < sn && strcmp(t, s[j]); j++);
            if(j < sn) c[j]++;
            else
            {
                strcpy(s[sn], t);
                c[sn++] = 1;
            }
        }
        for(n = j = i = 0; i < sn; i++)
            if(j < c[i]) j = c[i], n = i;
    }
    return 0;
}

重剑无锋,大巧不工
2015-04-05 22:02
快速回复:(ACM题)结果正确,但反馈wrong answer。怎么回事?
数据加载中...
 
   



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

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