paizaラーニングのレベルアップ問題集「条件分岐メニュー」からの出典です。
paiza.jp
Pythonによる「積の最小化」問題集と、それらの提出コードの解答例です。
僕が作成、提出したコードは、以下のとおりです。
・STEP: 1 けた数の測定
/* Pythonによる「条件分岐メニュー」問題集(積の最小化) STEP: 1 けた数の測定 https://paiza.jp/works/mondai 提出コードの解答例 https://neguse-atama.hatenablog.com */ # coding: utf-8 s = input() print(len(s))
・STEP: 2 足したり引いたり
/* Pythonによる「条件分岐メニュー」問題集(積の最小化) STEP: 2 足したり引いたり https://paiza.jp/works/mondai 提出コードの解答例 https://neguse-atama.hatenablog.com */ # coding: utf-8 n, a, b = input().split(' ') n = int(n) a = int(a) b = int(b) ans1 = n + a + b ans2 = n + a - b ans3 = n - a + b ans4 = n - a - b if ans1 == 0 or ans2 == 0 or ans3 == 0 or ans4 == 0: print("YES") else: print("NO")
・STEP: 3 同値判定
/* Pythonによる「条件分岐メニュー」問題集(積の最小化) STEP: 3 同値判定 https://paiza.jp/works/mondai 提出コードの解答例 https://neguse-atama.hatenablog.com */ # coding: utf-8 n = int(input()) s1 = input().rstrip().split(' ') s2 = input().rstrip().split(' ') count = int(0) for i in range(n): if s1[i] == s2[i]: count += 1 print(count)
・STEP: 4 終了判定
/* Pythonによる「条件分岐メニュー」問題集(積の最小化) STEP: 4 終了判定 https://paiza.jp/works/mondai 提出コードの解答例 https://neguse-atama.hatenablog.com */ # coding: utf-8 n = int(input()) lis = input().rstrip().split(' ') cnt = int(0) for i in range(len(lis)): n = int(lis[i]) if n%2 == 0: cnt = cnt + n else: break print(cnt)
・STEP: 5 終了判定 2
/* Pythonによる「条件分岐メニュー」問題集(積の最小化) STEP: 5 終了判定 2 https://paiza.jp/works/mondai 提出コードの解答例 https://neguse-atama.hatenablog.com */ # coding: utf-8 n,k = input().split(' ') n,k = int(n), int(k) ans = int(0) while n < k: n = n * 2 ans += 1 print(ans)
・STEP: 6 池の周回
/* Pythonによる「条件分岐メニュー」問題集(積の最小化) STEP: 6 池の周回 https://paiza.jp/works/mondai 提出コードの解答例 https://neguse-atama.hatenablog.com */ # coding: utf-8 n,k,t = input().split(' ') n,k,t = int(n), int(k), int(t) num = int(0) for i in range(t): num = num + k if num % n == 0: print("YES") else: print("NO")
・STEP: 7 崖に落ちるか判定
/* Pythonによる「条件分岐メニュー」問題集(積の最小化) STEP: 7 崖に落ちるか判定 https://paiza.jp/works/mondai 提出コードの解答例 https://neguse-atama.hatenablog.com */ # coding: utf-8 n,k,t = input().split(' ') n,k,t = int(n), int(k), int(t) if k*n <= t: print("YES") else: print("NO")
・STEP: 8 タイルの敷き詰め
/* Pythonによる「条件分岐メニュー」問題集(積の最小化) STEP: 8 タイルの敷き詰め https://paiza.jp/works/mondai 提出コードの解答例 https://neguse-atama.hatenablog.com */ # coding: utf-8 h,w = input().split(' ') h,w = int(h), int(w) if h == 0 or w == 0: print("NO") elif h%2 == 0 and w%2 == 0: print("YES") else: print("NO")
・FINAL問題: 積の最小化
/* Pythonによる「条件分岐メニュー」問題集(積の最小化) FINAL問題: 積の最小化 https://paiza.jp/works/mondai 提出コードの解答例 https://neguse-atama.hatenablog.com */ # coding: utf-8 a,b = input().split(' ') a,b = int(a), int(b) if a < 0 and b < 0: if a < b: print(b*b) else: print(a*a) elif a > 0 and b > 0: if a < b: print(a*a) else: print(b*b) else: print(a*b)
paizaラーニングのレベルアップ問題集については、ユーザー同士で解答を教え合ったり、コードを公開したりするのは自由としています。
また授業や研修、教材などにも利用できるそうです。