ABC148 - Atcoder/Python精進のための解説メモ
2022/12/27
ABC148 - A.Round One
AtCoder公式 | ABC148 - A.Round One解答
a = int(input())
b = int(input())
print(1 + 2 + 3 - a - b)
要点解説メモ
- シンプルに残ったやつを出力
ABC148 - B.Strings with the Same Length
AtCoder公式 | ABC148 - B.Strings with the Same Length解答
n = int(input())
s, t = map(str, input().split())
ans = ''
for i in range(n):
ans += s[i]
ans += t[i]
print(ans)
要点解説メモ
- 先に結合してスライスループしても良いけど、普通にforループでよさそう
ABC148 - C.Snack
AtCoder公式 | ABC148 - C.Snack解答
a, b = map(int, input().split())
def gcd(x, y):
if y == 0:
return x
else:
return gcd(y, x % y)
def lcm(x, y):
return (x * y) // gcd(x, y)
print(lcm(a, b))
別解
from fractions import gcd
a, b = map(int, input().split())
print(int(a * b / gcd(a, b)))
別解
import math
a, b = map(int, input().split())
print(math.lcm(a, b))
要点解説メモ
- 最大公約数を求めるgcd関数がpythonのバージョンアップデートでよく変わる
- コンテンスト開催当時だとfractionsにある
- python3.9以降はmathに3引数以上とれる、gcd,lcmがある
- ユークリッドの互除法を用いた自前の関数をもっておいたほうが安全かもしれない
ABC148 - D.
AtCoder公式 | ABC148 - D.解答
まだ解いていません