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?

問題概要

1x3のように数字、"x"、数字の順に並んだ文字列が与えられる。この時"x"をかけるとした時の掛け算の答えを出力する。

解法と実装

1. 文字列の最初と最後を見る

数字と"x"をまとめて文字列として受け取った後、それぞれをかけて計算します。
入力の時点では文字列なので、int()で数字にしています。

S = input() # Sに文字列を入力
print(int(S[0]) * int(S[2])) # Sの0文字目と2文字目を数字にしてかけて出力

2. 入力の時点で分ける

AtCoderでよく使うinput().split()では空白区切りの文字列を受け取ります。
input()の中を変えることで、入力の時点で2つの数字に分けることができます。

a, b = map(int, input().split("x")) # "x"区切りで数字を受け取る
print(a * b)
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?