peixx @ 2024-01-22 11:56:55
#include <stdio.h>
int main()
{
int s,v;
scanf("%d%d", &s, &v);
int lim = 24 * 60;
int time;
if (s % v == 0)
{
time = s / v;
}
else {
time = s / v + 1;
}
time = time + 10;
if (time >= lim)
{
return 0;
}
if (time < 60)
{
int realtime = 60 - time;
printf("\n");
printf("07:");
printf("%d", realtime);
}
if (time > 60)
{
int hour = time / 60;
int time1 = time % 60;
if (hour >= 8)
{
int realtime = 60- time1;
int hour1 = hour - 8;
printf("\n");
printf("%d:", 24-hour1-1);
printf("%d", realtime);
}
if (hour < 8)
{
int realhour = 8 - hour-1;
int realtime = 60 - time1;
printf("\n");
printf("0%d:", realhour);
if (realtime < 10)
{
printf("0%d", realtime);
}
if (realtime >= 10)
{
printf("%d", realtime);
}
}
}
}
by AnsonIsTheBest @ 2024-01-24 14:39:17
首先你没有考虑time=60的情况
然后为什么要输出\n,不用输出\n
可以不用考虑前一天晚上的情况,题干有讲,不过没事
然后real hour和real time赋值的地方没有考虑整小时的情况,比如正好要花一个小时,按照代码会变成6点60出发
修改后代码
#include <stdio.h>
int main()
{
int s,v;
scanf("%d%d", &s, &v);
int lim = 24 * 60;
int time;
if (s % v == 0)
{
time = s / v;
}
else {
time = s / v + 1;
}
time = time + 10;
if (time >= lim)
{
return 0;
}
if (time < 60)
{
int realtime = 60 - time;
printf("");
printf("07:");
printf("%d", realtime);
}
if (time > 60)
{
int hour = time / 60;
int time1 = time % 60;
if (hour >= 8)
{
int realtime = 60- time1;
int hour1 = hour - 8;
printf("");
printf("%d:", 24-hour1-1);
printf("%d", realtime);
}
if (hour < 8)
{
int temp=1;
if (time1==0)
{
temp=0;
}
int realhour = 8 - hour -temp;
int realtime = 60 - time1-(1-temp)*60;
printf("");
printf("0%d:", realhour);
if (realtime < 10)
{
printf("0%d", realtime);
}
if (realtime >= 10)
{
printf("%d", realtime);
}
}
}
}
然鹅我不知道为什么第三个点还是没过