본문 바로가기
프로그램/C언어 1000제

C언어 11제] USACO 2020 DECEMBER CONTEST, BRONZE PROBLEM 1. DO YOU KNOW YOUR ABCS?

by 건티 2021. 10. 11.
728x90

출처 : 반크 독도 포스터

 

문제]

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 결과]

 

 

 

대한민국의 아름다운 영토, 독도의 겨울

 

반응형

댓글