1
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?

問題概要

長方形の3辺が与えられる。
残りの1辺の長さを出力せよ。

解法と実装

長方形の辺の長さなので、3つのうち少なくとも2つは同じなので、残りの1つを出力すれば良いです。
これはif文で実装できます。

a, b, c = map(int, input().split()) # 入力を受け取り
if a == b: # aとbが等しいなら
  print(c) # 答えはc
elif b == c:
  print(a)
else:
  print(b)

リストとしてソートした時の、真ん中の値でない方が答えです。

A = list(map(int, input().split())) # リストとして3辺の長さを受け取る
A.sort() # Aをソート
if A[0] == A[1]: # 小さい2つが等しい時、一番大きいA[2]が答え
  print(A[2])
else:
  print(A[0])
1
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
1
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?