4
3

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 3 years have passed since last update.

Python3 競技プログラミング用 標準入力

Last updated at Posted at 2020-08-20

#概要
Python3の競プロ用によく使う標準入力のメモです。

参照するときに迷うことがなくなるように、コメント付きで1つのコードにまとめています。

#コード


'''
標準入力を受け取る方法まとめ
'''

#___文字列や数値をそのままほしい場合___#
# 文字列 1行1つ
s = input()

# 文字列 1行2つ
s, t = input().split()

# 整数 1行1つ
s = int(input())

# 整数 1行2つ
n, m = map(int, input().split())


#___リストでほしい場合___#
# リスト 文字列 1行
a = input().split()

# リスト 整数   1行
a = list(map(int, input().split()))

# リスト 文字列 nが指定行
a = [input() for i in range(n)]

# リスト 整数 nが指定行
a = [int(input()) for i in range(n)]

#___二次元配列でほしい場合___#
#2次元配列 文字列 nが指定行 空白区切りで複数行列
a = [input().split() for l in range(n)]


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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?