0
0

N 行 M 列の整数の入力 Python3編

Posted at

前回と似たような課題
https://paiza.jp/works/mondai/stdin_primer/stdin_primer__matrix_data_step4

1 行目で整数 N と整数 M が与えられます。
2 行目以降で N 行 M 列の行列が与えられます。上から i 番目、左から j 番目の整数は >a_{i,j} です。
N 行 M 列の行列をそのまま出力してください。

arr = list(map(int,input().split()))
N = arr[0]
M = arr[1]

arr = []
for i in range(N):
    value = list(map(int,input().split(" ")))
    arr.append(value)

for i in range(N):
    print(*arr[i])

内容としてはこれでOKなんだけど、
最初の部分はもっと簡単にできる方法があるそうだ。

N, M = map(int, input().split())

なるほど〜。これはもっと簡単になった。
覚えておこう。

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