ARC #02 を python で解いてみた!
AtCoder のRegular Contest 02 のA〜C問題を python3 で解いてみました。
D 問題はまだ実力的に無理でした...笑
問題は以下です↓↓
arc002.contest.atcoder.jp
汚いコードですが一応動きました。。笑
もし、優しい方がいらっしゃったら、「こうすればもっとうまく書けるよ」とかをコメントで教えていただけると嬉しいです。
A 問題:うるう年を調べる
Y = int(input()) if Y % 400 == 0: print("yes") elif Y % 100 == 0: print("no") elif Y % 4 == 0: print("yes") else: print("no")
B 問題:(年)が(月×日)で割り切れる一番近い日付を見つける
import datetime Y, M, D = [int(n) for n in input().split("/")] date_search = datetime.date(Y, M, D) for n in range(1, 365): td = datetime.timedelta(days = n) date_search_next = date_search + td y = date_search_next.year m = date_search_next.month d = date_search_next.day if y % (m * d) == 0: print(date_search_next) break
C 問題:A,B,X,Yのうち2文字の組を2つ作って文字列を短くする
import re N = input() command = input() button = ["A", "B", "X", "Y"] short_command = [] for x in command: for y in button: short_command.append(x + y) num = [] for i in range(15): L = short_command[i] command_1 = re.sub(L, "L", command) for l in range(i+1, 16): R = short_command[l] command_2 = re.sub(R, "R", command_1) num.append(len(command_2)) print(min(num))