poj1563---蜗牛爬井
#include <stdio.h> #include <stdlib.h> int main() { int dayTh; float Udis,currentHeight,firstClaim,HeightOfWell,downDis,fagtigue; while(scanf("%f %f %f %f",&HeightOfWell,&Udis,&downDis,&fagtigue)!=EOF){ if(HeightOfWell==0) break; currentHeight=0; firstClaim=Udis; dayTh=0; while(1){ currentHeight+=Udis; Udis-=fagtigue/100*firstClaim; if(Udis<0) Udis=0; dayTh++; if(currentHeight>HeightOfWell){ printf("success on day %d\n",dayTh); break; } else{ currentHeight-=downDis; if(currentHeight<0) { printf("failure on day %d\n",dayTh); break; } } } } return 0; }
WA过,注意当Udis<0,Udis=0;变量都赋值成float