[백준/파이썬] 11131번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 11131번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
Ever since you started studying, your whole family have been expecting you to know the answers to a whole lot of difficult questions. What is wrong with my computer? What is the name of Prince Harry’s new girlfriend? Have you seen my new pants? Your grandfather has just found a new problem for you, and you are yet again under the pressure of finding the answers to one of life’s most fundamental questions.
You are given a 20 meter long lever balanced exactly on the middle by a massless support. A number of weights are applied to the lever. …
입력 요약
The first line of input contains a single number T, the number of test cases to follow. Each test case starts with a line containing N, the number of weights in the test case. This is followed by a line containing N numbers, W1 W2 … …
출력 요약
For each test case, output one line containing Left if the weight tips to the left, Right if the weight tips to the right or Equilibrium if the weight does not tip to any of the sides.
코드
import sys;read=sys.stdin.readline
for T in range(int(read())):
read()
s=sum(map(int,read().split()))
if s>0:r='Right'
elif s<0:r='Left'
else:r='Equilibrium'
print(r)
설명
핵심은 구현 관점에서 Ever since you started studying, your whole family have been expecting you to know the answers to a whole lot of difficult questions. …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기