题目:
八尾勇喜欢吃苹果。她现在有 m(1≤m≤100)个苹果,吃完一个苹果需要花费 t(0≤t≤100)分钟,吃完一个后立刻开始吃下一个。现在时间过去了 s(1≤s≤10000)分钟,请问她还有几个完整的苹果?
输入:三个非负整数,m,t,s
输出:一个整数表示答案
注意点:
1、吃苹果花费的时间可以等于0;
2、最后答案需要的是完整的苹果;
记录自己思路用的,我知道写的有些累赘了,所以这个代码没有什么参考价值
#include <stdio.h>
int main(void)
{
int apple_m, apple_t, apple_s;
//苹果的数量,吃一个苹果要花的时间,已经过去的时间
int remainder = 0;//剩余的,初始化为0
scanf("%d%d%d", &apple_m, &apple_t, &apple_s);
//输入数据
if (apple_m * apple_t > apple_s)
{
if (apple_s >= apple_t && apple_t != 0)
{
if (apple_s % apple_t == 0)
{//判断时间取余是否等于0,如果等于0,剩下的苹果都是完整的
remainder = apple_m - (apple_s / apple_t);
}
else
{//不等于0,证明剩下了一个不完整的苹果,需要为最终结果减一
remainder = apple_m - (apple_s / apple_t) - 1;
}
}
//过去的时间比吃苹果的时间大
else if (apple_t == 0)
{
//假设一瞬间吃掉一个苹果
;
}
if (apple_s < apple_t)
{
remainder = apple_m - 1;
}
//过去的时间比吃苹果的时间少,那么一个苹果也吃不完,但是剩余完整的苹果要比原来少一
}
else
{
;
}
printf("%d", remainder);
return 0;
}