0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

paizaラーニング「足したり引いたり Python3編」

Posted at

私の回答

n,a,b=map(int,input().split())
if (n+a+b==0) or (n+a-b==0) or (n-a+b==0) or (n-a-b==0):
    print("YES")
else:
    print("NO")

模範解答

n, a, b = [int(x) for x in input().split()]

if n + a + b == 0:
    print("YES")
elif n + a - b == 0:
    print("YES")
elif n - a + b == 0:
    print("YES")
elif n - a - b == 0:
    print("YES")
else:
    print("NO")
  • 本問題は N ± A ± B が 0 になるか判定する問題です。
  • Nが 0 になる場合は全部で 4 通り考えられます。
    1. N + A + Bが 0 になる場合
    2. N + A - Bが 0 になる場合
    3. N - A + Bが 0 になる場合
    4. N - A - Bが 0 になる場合
  • これらをすべて試して、どれかが 0 になる場合はYESを出力します。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?