LoginSignup
4
1

More than 1 year has passed since last update.

[Atcoder]python3の入力処理方法

Last updated at Posted at 2022-04-03

3/26からAtCoder始めました。対戦よろしくお願いいたします。
AtCoderの入力方法は標準入力です。
普段、標準入力はあまりしないので、戸惑ってしまいました。
そのため、主な入力処理パターンをまとめました

入力個数が1つ(ex 1)

# int
a = int(input())
# str
a = str(input())

入力個数が決まっているパターン(ex A B C Dが与えられるパターン)

# int
a, b, c, d = map(int, input().split())
# str
a, b, c, d = str(int, input().split())

個数が指定されない場合(ex. A1~Anの個数が当たられるパターン)

# int
An = list(map(int,input().split()))
# str
Bn = list(map(str,input().split()))

1つ目に個数、2つ目以降にリストがある場合(n k1 k2 k3 .... kn)の場合

n, *kn = map(int, input().split())

文字列分割の場合

#ABCD
a = list(input())
# a = ["A","B","C","D"]

楽しく競技プログラミングしましょう!

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