0
1

More than 3 years have passed since last update.

paizaとか競技プログラミングで使う標準入力をintで一括取得する(python)

Last updated at Posted at 2020-01-24

paizaとか競技プログラミングやっている時用の標準入力受け取り&int化。
入力値は1 2 3の様に間にスペースが入ってたりすることを想定してます。
input使うのがなんか嫌なのでsys使ってます。実行速度もsys使った方が速いのでいいのかなぁと。
実行時間の比較は別記事にしてます。pythonの標準入力受け取りinput()とsys.stdinはどっちがいいの?

1行の場合.py
data = [int(s) for s in sys.stdin.readline().split()]
複数行の場合.py
data = list()
for l in sys.stdin:
    data.append([int(i) for i in l.split()])
#1行で書くと↓
data = [ [int(s) for s in line.split()] for line in sys.stdin ]
0
1
2

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
1