题目:
八尾勇喜欢吃苹果。她现在有 m(m≤100) 个苹果,吃完一个苹果需要花费 t(1≤t≤100) 分钟,吃完一个后立刻开始吃下一个。现在时间过去了 s(s≤10000) 分钟,请问她还有几个完整的苹果?
问题描述
第二个测试点过不了
#include<iostream>
using namespace std;
int main()
{
int m, t, s;
cin >> m >> t >> s;
if (t == 0) //t=0的情况
{
cout << m << endl;
}
else if (s >= m * t) //吃完还剩余时间
{
cout << 0 << endl;
}
else
{
if (s % t == 0) //刚好吃完了整数个
cout << m - s / t << endl;
else //正在吃
cout << m - 1 - s / t << endl;
}
return 0;
}
原因分析:
因为理解错了T^T,当t=0时,表示0分钟吃完,那么t不能做除数而且苹果剩余0个,我以为是没吃……
解决方案:
t=0时,直接输出0就可以了。嗯,这题考阅读理解。。。
#include<iostream>
using namespace std;
int main()
{
int m, t, s;
cin >> m >> t >> s;
if (t == 0) //t=0的情况
{
cout << 0 << endl;
}
else if (s >= m * t) //吃完还剩余时间
{
cout << 0 << endl;
}
else
{
if (s % t == 0) //刚好吃完了整数个
cout << m - s / t << endl;
else //正在吃
cout << m - 1 - s / t << endl;
}
return 0;
}