LoginSignup
0
0

More than 3 years have passed since last update.

Python3 標準入力 まとめてみた

Last updated at Posted at 2020-02-02

はじめに

競技プログラミングを最近始めたので案外めんどくさい標準入力についてまとめました。
出力とかの処理についてはあとできれいに直します。

input高速化

高速化
import sys
input = sys.stdin.readline

単純な入力

input
apple
orange 
10
12.5
a = input()
b = str(input())
c = int(input())
d = float(input())

List型

input
1
2
3
4
5
X = [int(input()) for i in range(5)]
print(X)
output
[1, 2, 3, 4, 5]
input
1 2 3 4 5
A = list(map(int,input().split()))
print(A)
output
[1, 2, 3, 4, 5]

List in 〇〇

List in tuple

l = []
n = int(input())
for i in range(n):
    a,b=input().split()
    l.append((int(a), b))

List in list(int)

n = int(input())
arr = []
for i in range(n):
    arr.append(list(map(int, input().rstrip().split())))

List in list(str)

N = int(input()) 
arr = [list(map(str, input().split())) for i in range(N)]
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