user-0 提问: 跪求大牛查错poj1006 感觉都对呀 虽然办法很笨 输出应该是对的 WA了N次了 快崩溃了

回复:
user: user-1
content: 测试用例是从网上搜来的.有了反例,就容易分析了.

user: user-0
content: 引用 2 楼 logiciel 的回复:LZ程序不能通过以下测试用例:  19 0 1 364 24 29 34 1  如下修改2处可AC: #include<stdio.h> #define N 21252 typedef struct{   int amount;   int period; }bio,*pbio;  int main(){   bio ph,em,in;   int p,e,i,d,co;   ph.period=23;   em.period=28;   in.period=33;   co=1;   scanf("%d %d %d %d",&p,&e,&i,&d);   while(p>=0&&e>=0&&i>=0&&d>=0){     if(p==e&&p==i){       printf("Case %d: the next triple peak occurs in %d days.\n",co,p>d?p-d:N+p-d);     }else{       ph.amount=p;       em.amount=e;       in.amount=i;        /* while(ph.amount<21253&&em.amount<21253&&in.amount<21253){         if(ph.amount==em.amount&&em.amount==in.amount){           break;         }       改为以下1行*/       while(ph.amount!=em.amount||em.amount!=in.amount){           if(ph.amount>=em.amount&&ph.amount>=in.amount){           if(em.amount>in.amount){             in.amount+=in.period;           }else{             em.amount+=em.period;           }         }else{           if(em.amount>=ph.amount&&em.amount>=in.amount){             if(ph.amount>in.amount){               in.amount+=in.period;             }else{               ph.amount+=ph.period;             }           }else{             if(ph.amount>em.amount){               em.amount+=em.period;             }else{               ph.amount+=ph.period;             }           }         }         //               printf("%d %d %d\n",ph.amount,em.amount,in.amount);       }       //           printf("%d %d %d\n",ph.amount,em.amount,in.amount);        //改为以下2行 printf("Case %d: the next triple peak occurs in %d days.\n",co,ph.amount-d?ph.amount-d:ph.amount);       ph.amount=ph.amount%N;       printf("Case %d: the next triple peak occurs in %d days.\n",co,ph.amount>d? ph.amount-d : N+ph.amount-d);      }     scanf("%d %d %d %d",&p,&e,&i,&d);     co++;   }    return 0; } 万分感谢，，大牛就是大牛。请问您是怎么做测试的呀，怎么去发现错误的呢

user: user-1
content: LZ程序不能通过以下测试用例:  19 0 1 364 24 29 34 1  如下修改2处可AC: #include<stdio.h> #define N 21252 typedef struct{   int amount;   int period; }bio,*pbio;  int main(){   bio ph,em,in;   int p,e,i,d,co;   ph.period=23;   em.period=28;   in.period=33;   co=1;   scanf("%d %d %d %d",&p,&e,&i,&d);   while(p>=0&&e>=0&&i>=0&&d>=0){     if(p==e&&p==i){       printf("Case %d: the next triple peak occurs in %d days.\n",co,p>d?p-d:N+p-d);     }else{       ph.amount=p;       em.amount=e;       in.amount=i;        /* while(ph.amount<21253&&em.amount<21253&&in.amount<21253){         if(ph.amount==em.amount&&em.amount==in.amount){           break;         }       改为以下1行*/       while(ph.amount!=em.amount||em.amount!=in.amount){           if(ph.amount>=em.amount&&ph.amount>=in.amount){           if(em.amount>in.amount){             in.amount+=in.period;           }else{             em.amount+=em.period;           }         }else{           if(em.amount>=ph.amount&&em.amount>=in.amount){             if(ph.amount>in.amount){               in.amount+=in.period;             }else{               ph.amount+=ph.period;             }           }else{             if(ph.amount>em.amount){               em.amount+=em.period;             }else{               ph.amount+=ph.period;             }           }         }         //               printf("%d %d %d\n",ph.amount,em.amount,in.amount);       }       //           printf("%d %d %d\n",ph.amount,em.amount,in.amount);        //改为以下2行 printf("Case %d: the next triple peak occurs in %d days.\n",co,ph.amount-d?ph.amount-d:ph.amount);       ph.amount=ph.amount%N;       printf("Case %d: the next triple peak occurs in %d days.\n",co,ph.amount>d? ph.amount-d : N+ph.amount-d);      }     scanf("%d %d %d %d",&p,&e,&i,&d);     co++;   }    return 0; }

user: user-2
content: 设置断点，逐步调试，分析结果。 这是必须掌握的技能。对你以后遇到类似问题更加容易处理。