1
0

More than 3 years have passed since last update.

python3 配列を数値に変換して計算する (記録)

Posted at

2つの整数の組がn個与えられるので、各組の計算結果を足し合わせたものを出力してください。

各組の計算結果は次の値です。
・2つの整数の組を足し合わせたもの
・ただし、2つの整数が同じ値だった場合は、掛け合わせたもの

time = int(input())
result = 0

for i in range(time):
    std_in = input()
    array = std_in.split()

    if array[0] == array[1]:
        result += int(array[0]) * int(array[1])
    else:
        result += int(array[0]) + int(array[1])

print(result)

入力例1
5
2 1
3 6
4 2
4 4
4 70

出力例1
108

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