728x90
6721번: Backward numbers
Backward numbers are numbers written in ordinary Arabic numerals but the order of the digits is reversed. The first digit becomes the last, and vice versa. For example, the number 1245 becomes 5421. Note that all leading zeroes are omitted. This means that
www.acmicpc.net
문제 풀이
주어진 두 입력값을 거꾸로 뒤집어서 합을 구해준 뒤, 그 합을 다시 뒤집어서 출력해주면 된다.
정답 코드
for _ in range(int(input())) :
a, b = input().split()
bw_a, bw_b = "", ""
for i in range(len(a) - 1, -1, -1) : bw_a += a[i]
for i in range(len(b) - 1, -1, -1) : bw_b += b[i]
bw_sum = int(bw_a) + int(bw_b)
ans = ""
for i in range(len(str(bw_sum)) - 1, -1, -1) : ans += str(bw_sum)[i]
print(int(ans))
728x90
'Algorithm > PS' 카테고리의 다른 글
[BOJ/백준] 6779 - Who Has Seen The Wind [python] (0) | 2023.03.19 |
---|---|
[BOJ/백준] 6750 - Rotating letters [python] (0) | 2023.03.19 |
[BOJ/백준] 6437 - Golf [python] (0) | 2023.03.17 |
[BOJ/백준] 6378 - 디지털 루트 [python] (0) | 2023.03.17 |
[BOJ/백준] 6322 - 직각 삼각형의 두 변 [python] (0) | 2023.03.17 |