标题:(ACM题)结果正确,但反馈wrong answer。怎么回事?
取消只看楼主
赤云
Rank: 2
等 级:论坛游民
帖 子:82
专家分:35
注 册:2014-12-29
结帖率:64.71%
 问题点数:0 回复次数:0 
(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



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




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

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