题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1302
C语言源码:
#include<stdio.h>
int main()
{
float i,h,u,d,f,length,pre;
int day;
scanf("%f%f%f%f",&h,&u,&d,&f);
while(h)
{
day=1;
length=u;
pre=u;
while(length>=0&&length<=h)//注意有等号!
{
length-=d;
if(length<0)
break;
pre-=f*u/100.0;
pre=(pre>=0?pre:0);
length+=pre;
day++;
}
if(length<0)
printf("failure ");
else
printf("success ");
printf("on day %d\n",day);
scanf("%f%f%f%f",&h,&u,&d,&f);
}
}