백준 알고리즘 1~2단계 (입출력과 사칙연산, 조건문)

김형준·2022년 4월 6일
0
post-thumbnail
  • 새로 공부한 내용
a = input().split()
a, b = map(int, input.split())

# a에 입력된 값은 리스트에 스트링으로 담겨 저장된다. 따라서 a를 integer로 쓰기 위해 int()로 형변환을 해준다.

# map()함수는 map(함수, 반복 가능한 객체)로 사용한다. 여기에선 입력한 값을 int로 형변환한다는 의미로 사용한 것이 된다.

# 주의할 점은 map은 인덱싱이 불가능하기 때문에 이를 다시 리스트에 담아주는 과정이 필요하다는 것이다.

a = list(map(int, a))

# 추가적으로 입력할 값이 반복문에 의해 많아진다면 시간이 많이 소요되기에 input()대신 sys.stdin.readline()을 써준다.

#백준 알고리즘 15552번 문제
import sys

T = int(input())
for i in range(T):
	a,b = map(int, sys.stdin.readline().split()
    print(a+b)

참조
1) https://velog.io/@suasue/Python-map-%ED%95%A8%EC%88%98
2) https://velog.io/@yeseolee/Python-%ED%8C%8C%EC%9D%B4%EC%8D%AC-%EC%9E%85%EB%A0%A5-%EC%A0%95%EB%A6%ACsys.stdin.readline

profile
BackEnd Developer

0개의 댓글