LoginSignup
0
1

Python標準入力チートシート [AtCoder]

Posted at

目次

はじめに

自分が使うものを、自分のために書いてます。
より良いものがあれば、コメントしていただけると幸いです。

チートシート

1行の整数を受け取る

入力 code 備考
N N = int(input()) 整数(N)
N M N,M = map(int,input().split()) 整数(N,M)

1行の配列・文字列を受け取る

入力 code 備考
A1 A2 A3...An A= list(map(int,input().split())) Ak : 整数
helloworld s = input() ->'helloworld' print(s[5])=>wのように取得可
helloworld s = list(input()) s = ['h','e','l','l','o','w','o','r','l','d']

整数を受け取る・グラフ問題

〜入力〜
4 3 #N M
1 2
3 2
1 3

code
N,M = map(int,input().split())
node = [[] for _ in range(N)]

for _ in range(M):
    u,v = map(int, input().split())
    u-=1
    v-=1
    node[u].append(v)
    node[v].append(u)
#node<-[1, 2], [0, 2], [1, 0], []]

複数行の文字列を受け取る

〜入力〜
3
apple
black
sample

code
N=int(input())
strlist=[input() for i in range(N)]
#strlist<-['apple','black','sample']

print(strlist[1])=>black
print(strlist[1][0])=>b

グリッドを受け取る

〜入力〜
3 4 #H,W
.#..
#..#
..#.

code
H, W = map(int, input().split())
S = [input() for _ in range(H)]

S[0][1] =>'#'
S[1][0] => '#' のように取得可

おわりに

追記していきます。

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