This is a standard input memo used in competition pros and coding tests. The top is the input and the bottom is the source code.
Python3's built-in function ʻinput () is a function that gets the input from the keyboard as a character string. When the input becomes multiple lines as shown below, ʻinput ()
is fetched one line each time.
Click here for details (Official document)
99
hi
N = input()
M = input()
# N = '99'
# M = 'hi'
N
N = int(input())
N M
N, M = map(int, input().split())
A_1 A_2 ... A_N
A = list(map(int, input().split()))
It is also possible below (please refer to the last reference article etc. for operation)
*A, = map(int, input().split())
N
A_1
A_2
...
A_N
N = int(input())
A = [int(input()) for _ in range(N)]
N
P_(1,1) P_(1,2) ... P_(1,M)
...
P_(N,1) P_(N,2) ... P_(N,M)
N = int(input())
P = [list(map(int, input().split())) for _ in range(N)]
K S_1 S_2 ... S_N
K, *S = list(map(int, input().split()))
# K = K
# S = [S_1, S_2, ... S_N]
The * S
is said to be unpacked (on the list).
The asterisk *
in Python was described in detail in the following article.
-Reverse asterisk lookup for Python 3.x -[Introduction to Python 3] * (Asterisk) Summary of 1 function
Recommended Posts