[백준/파이썬] 11772번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 11772번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
The teacher has sent an e-mail to her students with the following task:
“Write a programme that will determine and output the value of (X) if given the statement:
[X = number_1^{pot_1} + number_2^{pot_2} + \dots + number_N^{pot_N}]
and it holds that (number_1), (number_2) to (number_N) are integers, and (pot_1), (pot_2) to (pot_N) one-digit integers.” Unfortunately, when the teacher downloaded the task to her computer, the text formatting was lost so the task transformed into a sum of (N) integers:
[X = P_1 + P_2 + … …
입력 요약
The first line of input contains the integer (N) (1 ≤ (N) ≤ 10), the number of the addends from the task. Each of the following (N) lines contains the integer (P_i) (10 ≤ (P_i) ≤ 9999, (i) = 1 … (N)) from the task.
출력 요약
The first and only line of output must contain the value of (X) ((X) ≤ 1 000 000 000) from the original task.
코드
s=0
for i in range(int(input())):
p=input()
s+=int(p[:-1])**int(p[-1])
print(s)
설명
핵심은 구현 관점에서 The teacher has sent an e-mail to her students with the following task: …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기