출처 : 반크 독도 포스터
문제]
Farmer John's cows have been holding a daily online gathering on the "mooZ" video meeting platform. For fun, they have invented a simple number game to play during the meeting to keep themselves entertained.
Elsie has three positive integers A, B, and C (A≤B≤C). These integers are supposed to be secret, so she will not directly reveal them to her sister Bessie. Instead, she gives Bessie seven (not necessarily distinct) integers in the range 1…10^9, claiming that they are A, B, C, A+B, B+C, C+A, and A+B+C in some order.
Given a list of these seven numbers, please help Bessie determine A, B, and C. It can be shown that the answer is unique.
INPUT FORMAT (input arrives from the terminal / stdin):
The only line of input consists of seven space-separated integers.
OUTPUT FORMAT (print output to the terminal / stdout):
Print A, B, and C separated by spaces.
SAMPLE INPUT:
2 2 11 4 9 7 9
SAMPLE OUTPUT:
2 2 7
SCORING:
Test cases 2-3 satisfy C≤50.
Test cases 4-10 satisfy no additional constraints.
Problem credits: Benjamin Qi
출처 : USACO 2020 DECEMBER CONTEST, BRONZE
참고풀이1]
import sys
L=list(map(int,input().split(' ')))
L.sort()
#1~10^9사이의 수가 아니면 작업을 끝낸다.
for A in L:
if A<1 or A>1000000000:
sys.exit()
#7개가 조건에 맞는 지 체크하고 맞으면 출력한다.
#A,B,C(A<=B<=C)
#A+B, B+C, C+A, A+B+C
for A in L:
for B in L[1:]:
for C in L[2:]:
if A+B in L and B+C in L and C+A in L and A+B+C in L:
print(A,B,C)
sys.exit()
참고풀이1 결과]
참고풀이2]
import sys
L=sorted(list(map(int,input().split(' '))))
#1~10^9사이의 수가 아니면 작업을 끝낸다.
for A in L:
if A<1 or A>1000000000:
sys.exit()
#A,B,C(A<=B<=C)
A=L[0]
B=L[1]
C=L[-1]-A-B
print(A,B,C)
참고풀이2 결과]
대한민국의 아름다운 영토, 독도의 봄
'프로그램 > Python 1000제' 카테고리의 다른 글
Python 26제] 2021년 한국정보올림피아드 1차 대회 1교시 중등부 사고력 문제 3. 함수 값 구하기 (0) | 2021.10.26 |
---|---|
Python 25제] 2021년 한국정보올림피아드 1차 대회 1교시 중등부 사고력 문제 1. 다른 모자 쓰기 (0) | 2021.10.22 |
Python 23제] 깊이 우선 탐색을 활용한 막대자르기 (0) | 2021.10.05 |
Python 22제] 파워 유저를 위한 파이썬 EXPRESS] p180 CHAPTER 4. 도전문제 (0) | 2021.09.24 |
Python 21제] 파워 유저를 위한 파이썬 EXPRESS] p170 CHAPTER 4. 도전문제 (0) | 2021.09.17 |
댓글