def sol(s1, s2):
ans = ''
if len(s1)<len(s2):
s1=s1.zfill(len(s2))
else:
s2 = s2.zfill(len(s1))
for i in range(len(s1)):
ans+= str(int(s1[i])+int(s2[i]))
return ans
s1,s2=map(str, input().split())
print(sol(s1,s2))
https://www.acmicpc.net/problem/8949
8949번: 대충 더해
두 정수 A, B가 공백을 두고 주어진다. A와 B는 1과 1,000,000 사이의 정수이다.
www.acmicpc.net
Type casting 과 숫자가 자리가 다를경우 앞에 0을 채워줘야하는데 이때 string.zfill() 함수 사용하면 편합니다
In number's length are different , You can use zfill() function, and type casting
https://docs.python.org/3/library/stdtypes.html
Built-in Types — Python 3.10.8 documentation
Built-in Types The following sections describe the standard types that are built into the interpreter. The principal built-in types are numerics, sequences, mappings, classes, instances and exceptions. Some collection classes are mutable. The methods that
docs.python.org
반응형
'python-algorithm' 카테고리의 다른 글
백준 25704 출석 이벤트 (0) | 2022.10.26 |
---|---|
백준 9253 스페셜 저지 (0) | 2022.10.25 |
백준 2154 수 이어 쓰기 3 (0) | 2022.10.23 |
백준 10205 헤라클레스와 히드라 (0) | 2022.10.22 |
백준 25640 MBTI (0) | 2022.10.21 |
댓글