If the fatigue factor drops the snail’s climbing distance below zero, the snail does not climb at all that day.
In other words, the snail’s height will exceed the height of the well or become negative.
代码
#include <stdio.h>int test(int h, int u, int d, int f, int* day)
{
*day = 0;
double ks = u, s = 0;
while (++*day) {
s += ks;
if (s > h) return1;
s -= d;
if (s < 0) return0;
ks -= f/100.0 * u;
if (ks < 0) ks = 0;
}
}
int main(void)
{
int h, u, d, f, day;
while (scanf("%d%d%d%d", &h, &u, &d, &f), h) {
printf(test(h, u, d, f, &day)? "success": "failure");
printf(" on day %d\n", day);
}
return0;
}