HZT1121 @ 2024-05-01 19:35:39
// P5707
# include <cstdio>
using namespace std;
int main()
{
int s, v, t;
scanf("%d %d", &s, &v);
if(s % v == 0)
t = (s / v);
else
t = (s / v) + 1;
if(t >= 24 * 60) t -= 24 * 60;
int t2 = 480;
t = t2 - 10 - t;
int x, f;
x = t / 60;
f = t % 60;
printf("%02d%c%02d", x, ':', f);
return 0;
}
by RH233 @ 2024-05-01 20:08:32
没有考虑到凌晨0点以前出发的情况(即用时大于480min). 例如当输入10000 5时,代码输出为-1:-30. 为了解决这个问题,需要进行特判
AC代码:
# include <cstdio>
using namespace std;
int main()
{
int s, v, t;
scanf("%d %d", &s, &v);
if(s % v == 0)
t = (s / v);
else
t = (s / v) + 1;
if(t >= 24 * 60) t -= 24 * 60;
int t2 = 480;
//t = t2 - 10 - t;负数.
if(t+10>t2) t=24*60-t-10+480;
else t=t2-10-t;
int x, f;
x = t / 60;
f = t % 60;
printf("%02d%c%02d", x, ':', f);
return 0;
}
by HZT1121 @ 2024-05-02 12:51:13
@RH233 谢谢,已AC,此贴完。