Settings | Sign in | Sign up

The author has 3 posts.

神奇鬧鐘

Floor 1 3/26/26 23:00
Floor 2 3/26/26 23:00

import os

import sys

from datetime import datetime,timezone

# 請在此輸入您的代碼

T=int(input())

for i in range(T):

  s=input().split()

  time=f"{s[0]} {s[1]}"

  x=int(s[2])

  dt=datetime.strptime(time,"%Y-%m-%d %H:%M:%S").replace(tzinfo=timezone.utc)

  ts=dt.timestamp()

  step=x*60

  target_ts = (ts // step) * step

  target_dt = datetime.fromtimestamp(target_ts, tz=timezone.utc)

    

  print(target_dt.strftime("%Y-%m-%d %H:%M:%S"))

Floor 3 3/26/26 23:01
原理不是很難理解,但是python要專門的時間函數,c來寫的話要多定義函數,麻煩,容易出錯

Content converter:

Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.