7
7

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

[python] 複数行の標準入力の処理

Last updated at Posted at 2017-10-11

paizaの問題で「複数行に渡る標準入力を受け取り、1行目と3行目以降の数字のペアを用いて、とある処理をせよ。ただし3行目以降の行数は2行目で指定される。」という問題がありました。標準入力の2行目以外を、int型の要素をもつリストで受け入れようとしたのですがハマってしまいました。以下そのメモ書きです。
参考URL:
http://codegeekboy.hateblo.jp/entry/paiza-input-python3

複数行の標準入力 2行目はそれより下の行数を表す
7 2
8 
1 4
1 1
10 4
2 2
9 4
8 10
9 10
7 4
output
[7, 2] 
8 
[[1, 4], [1, 1], [10, 4], [2, 2], [9, 4], [8, 1], [9, 1], [7, 4]]
parents = list(map(int,input().split(' ')))

N = int(input())
childs = [list(map(int, input().split())) for _ in range(N)]

"""冗長version
childs =[]
for i in range(N):
    
    line = list(map(int,input().split(' ')))
    childs.append(line)
"""

print(parents)
print(N)
print(childs)
7
7
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
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?