paizaラーニングのレベルアップ問題集「二重ループメニュー」からの出典です。
paiza.jp
Pythonによる「二重ループメニュー」問題集(活用編)と、それらの提出コードの解答例です。
僕が作成、提出したコードは、以下のとおりです。
・STEP: 1 行列の転置
''' Pythonによる「二重ループメニュー」問題集(活用編) ・STEP: 1 行列の転置 https://paiza.jp/works/mondai 提出コードの解答例 https://neguse-atama.hatenablog.com ''' # coding: utf-8 n, k = map(int, input().split()) lis = [] for i in range(n): s = list(map(int, input().split())) lis.append(s) for i in range(k): for j in range(n): if j < n-1: print(lis[j][i], end = " ") else: print(lis[j][i])
・STEP: 2 かけ算表
''' Pythonによる「二重ループメニュー」問題集(活用編) ・STEP: 2 かけ算表 https://paiza.jp/works/mondai 提出コードの解答例 https://neguse-atama.hatenablog.com ''' # coding: utf-8 n = int(input()) lis = list(map(int, input().split())) for i in range(n): for j in range(n): if j < n-1: print(lis[i]*lis[j], end = " ") else: print(lis[i]*lis[j])
・STEP: 3 素数の個数
''' Pythonによる「二重ループメニュー」問題集(活用編) STEP: 3 素数の個数 https://paiza.jp/works/mondai 提出コードの解答例 https://neguse-atama.hatenablog.com ''' # coding: utf-8 n = int(input()) cnt = 1 if n == 2: print(cnt) else: for i in range(2, n+1): for j in range(2, i): if i%j == 0: break if j == i-1: cnt+=1 print(cnt)
・STEP: 4 log2
''' Pythonによる「二重ループメニュー」問題集(活用編) STEP: 4 log2 https://paiza.jp/works/mondai 提出コードの解答例 https://neguse-atama.hatenablog.com ''' # coding: utf-8 n = int(input()) cnt = 0 for i in range(1, n+1): num = i while True: if num%2 != 0: break else: num/=2 cnt+=1 print(cnt)
・STEP: 5 スーパー鳩時計
''' Pythonによる「二重ループメニュー」問題集(活用編) STEP: 5 スーパー鳩時計 https://paiza.jp/works/mondai 提出コードの解答例 https://neguse-atama.hatenablog.com ''' # coding: utf-8 for t in range(24): for m in range(60): foo = t + m if foo%15 == 0: print("FIZZBUZZ") elif foo%3 == 0: print("FIZZ") elif foo%5 == 0: print("BUZZ") else: print()
・ STEP: 6 格子点
''' Pythonによる「二重ループメニュー」問題集(活用編) STEP: 6 格子点 https://paiza.jp/works/mondai 提出コードの解答例 https://neguse-atama.hatenablog.com ''' # coding: utf-8 lis = [] for x in range(1, 98): for y in range(1,98): if x**3 + y**3 < 100000: lis.append(x*y) lis.sort(reverse=True) print(lis[0])
・ STEP: 7 お金の支払い
''' Pythonによる「二重ループメニュー」問題集(活用編) STEP: 7 お金の支払い https://paiza.jp/works/mondai 提出コードの解答例 https://neguse-atama.hatenablog.com ''' # coding: utf-8 x, y, z = map(int, input().split()) ans = 3001 for i in range(1001): for j in range(1001): k = x*i + y*j if k <= z: l = z - k if i+j+l < ans: ans = i+j+l print(ans)
・FINAL問題: 二重ループ:活用編 三角形の探索
''' Pythonによる「二重ループメニュー」問題集(活用編) FINAL問題: 二重ループ:活用編 三角形の探索 https://paiza.jp/works/mondai 提出コードの解答例 https://neguse-atama.hatenablog.com ''' # coding: utf-8 n = int(input()) cnt = 0 for i in range(1,n-1): for j in range(1, n-i): k = n-(i+j) if i**2 == j**2 + k**2: cnt+=1 break if cnt == 0: print("NO") else: print("YES")
paizaラーニングのレベルアップ問題集については、ユーザー同士で解答を教え合ったり、コードを公開したりするのは自由としています。
また授業や研修、教材などにも利用できるそうです。