Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

代码清晰易懂,有注释,题目不难但查了n久还是WA,苦恼不已!请看出问题的不吝赐教,非常感谢啊~~!!!

Posted by Huacm42 at 2006-07-29 16:55:20 on Problem 2328
#include<stdio.h>
#include<string.h>
int main()
{
    int i,t[20],k,s,flag[20];
    char a[20];
    while(1)
    {
            s=0;k=0;i=0;
            for(i=0;i<20;i++)
            flag[i]=0;                  //初始化
            while(1)
            {                    
                    scanf("%d",&t[k]); 
                    fflush(stdin);
                    if(t[k]==0) {s=1;break;} //如果接受到0,s=1并跳出小循环
                    gets(a);
                    if(strcmp(a,"too low")==0) //如果是小,就变为-1
                     flag[k]=-1;
                    if(strcmp(a,"too high")==0) //如果是大,就变为1
                     flag[k]=1;
                    if(strcmp(a,"right on")==0)
                     break;
                    k++;
            }
            if(s==1) break; //如果接受到0,s变为1,结束整个循环
            i=0;
            for(i=0;i<k;i++)               //t[k]就是right on时得到的数
            {
                              if(t[i]>t[k]&&flag[i]==-1) break; //如果是大但flag[i]却为-1,矛盾
                              if(t[i]<t[k]&&flag[i]==1)  break; //如果是小但flag[i]却为1,矛盾
                              if(t[i]==t[k]) break; //如果没结束前就是本身,矛盾
            }                  
            if(i==k) printf("Stan may be honest\n"); //如果循环中没出现break,证明没有矛盾
             else printf("Stan is dishonest\n");
    }
    return 0;
}

                    

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator