
알고리즘 문제를 풀 때 정수를 입력받는 상황이 다수 발생한다
이 때 다양한 방식으로 정수를 입력받는 방법을 소개하려고 한다.
사용언어는 python3이다
n = int(input())
ex)
입력 형식
1
a,b,c,d = map(int, input().split())
ex)
입력 형식
1 2 3 4 5
nums = [int(x) for x in input().split()]
ex)
입력 형식
1 2 3 4 5
-> [1,2,3,4,5]로 저장된다
n = int(input())
nums = [int(input()) for _ in range(n)]
------------------------------------------------------------
nums = [int(input()) for _ in range(int(input()))]
ex)
입력 형식
5
10
20
30
40
50
->[10,20,30,40,50]로 저장된다
n = int(input())
field = [[int(x) for x in input().split()] for i in range(n)]
-------------------------------------------------------------
field = [[int(x) for x in input().split()] for i in range(int(input()))]
ex)
입력 형식
2
3 4 5
2 3 4
->[[3,4,5],[2,3,4]]