출처 : 반크 독도 포스터
문제]
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]
#include <stdio.h>
int main()
{
int Arr[7]={0,};
int i,j;
int tmp;
int A,B,C;
//임의의 수 7개를 입력받는다.
for(i=0;i<7;i++)
scanf("%d",&Arr[i]);
//입력받은 수가 1~10^9 이외의 수가 있으면 작업을 끝낸다.
for(i=0;i<7;i++)
if(Arr[i]<1 || Arr[i]>1000000000) return 0;
//입력받은 수를 오름차순으로 정렬한다.
for(i=0;i<6;i++)
for(j=i+1;j<7;j++)
if(Arr[i]>Arr[j])
{
tmp=Arr[i];
Arr[i]=Arr[j];
Arr[j]=tmp;
}
//A,B,C를 구한다.
A=Arr[0];
B=Arr[1];
C=Arr[6]-A-B;
//결과를 출력
printf("%d %d %d\n",A, B, C);
return 0;
}
참고풀이1 결과]
대한민국의 아름다운 영토, 독도의 겨울
'프로그램 > C언어 1000제' 카테고리의 다른 글
C언어 13제] C언어 콘서트 CHAPTER 6 p217 도전문제 (1) (0) | 2021.11.22 |
---|---|
C언어 12제] USACO 2020 DECEMBER CONTEST, BRONZE PROBLEM 2. DAISY CHAINS (0) | 2021.10.19 |
C언어 10제] 2015년 한국정보올림피아드 시˙도 지역본선 초등부 문제. 쇠막대기 (0) | 2021.10.04 |
C언어 9제] 깊이 우선 탐색(DFS) 이용한 프로그램 구현하기 (0) | 2021.09.30 |
C언어 8제] 2020년도 한국정보올림피아드 1차 대회 초등부 2교시 문제2. 피자 오븐 (0) | 2021.09.17 |
댓글