2009-01-17 22:42:08來源不明

ACM 573 The Snail

題目要看清楚啊,不然會眼花花找不到錯誤!

/*************************************************************/

  1. #include<stdio.h>   
  2. #include<stdlib.h>   
  3. #include<string.h>   
  4. #include<math.h>   
  5. main()   
  6. {   
  7.  int flag,day;   
  8.  double f1,f,u,h,d,temp;   
  9.  while(scanf("%lf %lf %lf %lf",&h,&u,&d,&f)==4&&h!=0)   
  10.   {   
  11.    flag=0;temp=0;f1=u*f/100;day=0;   
  12.    while(flag==0)   
  13.     {   
  14.      day++;   
  15.      if(u<0) u=0;   
  16.      temp=temp+u;   
  17.      if(temp>h) {flag=1;break;}   
  18.      temp=temp-d;   
  19.      if(temp<0) {flag=-1;break;}   
  20.      u=u-f1;   
  21.     }   
  22.    if(flag==1) printf("success on day %d\n",day);   
  23.    else printf("failure on day %d\n",day);   
  24.   }   
  25.  return 0;   
  26. }