알고리즘
백준 10952번 파이썬 (python) : A+B - 5
새우하이
2020. 8. 14. 16:07
while 문을 사용해서 두 정수가 0 0 이 들어올때 까지 A+B를 계산해야 하는 문제
이를 위해서는 "1 1" 이라는 입력을 문자열로 받아서 split()함수를 사용해서 두 숫자를 분리하는 과정을 거쳐야한다.
그리고 분리한 값을 다시 int형으로 저장해야하는데.
map함수를 사용한다.
https://www.w3schools.com/python/ref_func_map.asp
Python map() Function
Python map() Function ❮ Built-in Functions Example Calculate the length of each word in the tuple: def myfunc(n): return len(n) x = map(myfunc, ('apple', 'banana', 'cherry')) Try it Yourself » Definition and Usage The map() function executes a specif
www.w3schools.com
import sys
A,B = map(int,sys.stdin.readline().split())
while(A!=0 and B!=0):
print(A+B)
A,B = map(int,sys.stdin.readline().split())
나는 if 문을 쓰기 싫어서 이렇게 코딩했는데
보통
import sys
while(True):
A,B = map(int,sys.stdin.readline().split())
if A == 0 and B == 0 : break;
print(A+B)
이런식으로들 많이 쓰는듯 하다