はじめに
プログラムコンテストの題材で、三角形の3辺の和の長さを整数で入力し、ピタゴラスの定理が成立する(直角三角形)かどうか判定するプログラムを実装しました。
ソースコード
ソースコードは下記になります
num = int(input())
count = 0
for b in range(1,num):
for c in range(1,num-b):
a = num - b - c
ans1 = pow(a,2)
ans2 = pow(b,2)
ans3 = pow(c,2)
ans4 = ans2 + ans3
if ans1 == ans4:
count += 1
if count >= 1:
print("YES")
else:
print("NO")
実行結果
実行結果は下記の画像です。
最後に
競技プログラミングの課題に挑戦しました