반응형
[ Contents ]
1. 문제 (링크 참조)
16727번: ICPC
The first line of the input contains two space-separated integers p1 and s1, where p1 and s1 are the number of goals scored by Persepolis and Esteghlal, respectively, in the first match in which Persepolis is the home team. The second line contains two spa
www.acmicpc.net
2. 문제 풀이
두 경기의 점수를 합산하고 승패를 판별하는 문제입니다. 단, 점수가 동일할 경우에는 'Away'에서 더 많은 점수를 낸 팀이 승리합니다. 그마저도 동일할 경우에만 패널티킥으로 승패를 결정합니다.
3. 코드
# 입력
p1, s1 = map(int, input().split())
s2, p2 = map(int, input().split())
# 출력
if p1+p2 > s1+s2:
print("Persepolis")
elif p1+p2 < s1+s2:
print("Esteghlal")
else: # 동점인 경우
if s1 > p2:
print("Esteghlal")
elif s1 < p2:
print("Persepolis")
else:
print("Penalty")
다소 조금 조건식이 복잡할 수 있지만, 하지만 문제의 요구사항을 차례차례 정리하면 쉽게 작성할 수 있습니다.
반응형
'Algorithm' 카테고리의 다른 글
[구현/수학] 백준 20353 Atrium - 파이썬(Python) (0) | 2022.08.25 |
---|---|
[DP/동적계획법] 백준 15486 퇴사 2 - 파이썬(Python) (0) | 2022.08.24 |
[구현/수학] 백준 14173 Square Pasture - 파이썬(Python) (0) | 2022.08.22 |
[문자열/탐색] 백준 14425 문자열 집합 - 파이썬(Python) (0) | 2022.08.21 |
[구현/수학] 백준 22015 金平糖 (Konpeito) - 파이썬(Python) (0) | 2022.08.20 |
댓글