Cランクレベルアップメニュー「文字列」私の回答
問題はこちら。
https://paiza.jp/works/mondai/c_rank_level_up_problems/c_rank_string_boss?language_uid=python3
なーんか長い気がするのですが。記録までに。
# coding: utf-8 # Your code here! num = int(input()) for i in range(num): #timeに現在時刻を、addに加える時間をリストとして記録 s = input().split( ) line = [] g = s[0].split(":") g1 = int(g[0]) g2 = int(g[1]) s1 = int(s[1]) s2 = int(s[2]) time = [g1 , g2] add = [s1 , s2] #print(time) #print(add) #分の計算(uphは繰上りを表す) if time[1]+add[1] >= 60: res_min = time[1] + add[1] - 60 uph = int(1) else : res_min = time[1] + add[1] uph = int(0) #時の計算 if time[0] + add[0] + uph >= 24: res_hour = time[0] + add[0] + uph - 24 else : res_hour = time[0] + add[0] + uph #resに計算結果を格納 res = [] res.append(res_hour) res.append(res_min) #print(res) out = [] #整形して出力。(1桁の数字の先頭に0を付ける) for j in range(2): if res[j] < 10: out.append("0"+str(res[j])) else : out.append(str(res[j])) print(out[0] + ":" + out[1])