只能通过前7个求调试

P5707 【深基2.例12】上学迟到

w3271830934 @ 2024-02-29 18:58:08

from math import ceil
s,v= map(int,input().split(' '))
t=ceil(s/v)
zong=t+10
su = 480 - zong
if zong == 480:
    print("00:00")
if su>0:
    shi = int(su/60)
    print(f"0{shi}:",end = "")
    if su - shi*60>=10:
        print( su - shi*60)
    else:
        print(f"0{su-shi*60}")
else:
    shi = -su
    x= 24- ceil(shi/60)
    if x>=10:
        print(f"{x}:",end = "")
    else:
        print(f"0{x}",end = '')
    f=60 - (shi - int(shi/60))
    if f>=10:
        print(f)
    else:
        print(f"0{f}")

by __Rickysun__ @ 2024-02-29 19:49:53

@w3271830934 我没啥办法(我用的是 C++),但我有一组能 hack 你代码的数据:

in:

470 1

out: 正确输出:

00:00

你的输出:

00:00
24:60

我猜测可能是判断条件的问题


by w3271830934 @ 2024-02-29 21:55:05

@Rickysun 感谢回复,问题是下面这段

 f=60 - (shi - int(shi/60))

应该是

    f=60 - (shi - int(shi/60)*60)

并且用02d占位符修改后,代码如下

from math import ceil
s,v= map(int,input().split(' '))
t=ceil(s/v)
zong=t+10
su = 480 - zong
if su>=0:
    shi = su//60
    m=su - shi*60
    print(f"{shi:02d}:{m:02d}")
else:
    shi = -su
    x= 24- ceil(shi/60)
    f=60 - (shi - int(shi/60)*60)
    print(f"{x:02d}:{f:02d}")

|