xz07218 @ 2023-10-13 20:08:06
#include <stdio.h>
#include <math.h>
int main()
{int s,v,t,T,time;
scanf("%d %d",&s,&v);
if(s%v!=0)
{t=(s/v)+1;}
else
{t=s/v;}
T=t+10;
time=480-T;
int hour,minute;
hour=time/60;
minute=time%60;
if(hour<10)
printf("0%d:%d",hour,minute);
else
printf("%d:%d",hour,minute);
return 0;
}
by CtrlEEE @ 2023-10-13 20:27:16
T有可能会大于480,所以应该对time是否小于0作判断。
if (time >= 0) {
cout << setfill('0') << setw(2) << time / 60 << ":" << setfill('0') << setw(2) << time % 60 << endl;
}
if (time < 0) {
time += 24 * 60;
cout << setfill('0') << setw(2) << time / 60 << ":" << setfill('0') << setw(2) << time % 60 << endl;
}