列表

详情


NC222481. [USACODec20B]DoYouKnowYourABCs?

描述

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…109, 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.

输入描述

The only line of input consists of seven space-separated integers.

输出描述

Print A, B, and C separated by spaces.

示例1

输入:

2 2 11 4 9 7 9

输出:

2 2 7

说明:

Test cases 2-3 satisfy C≤50.
Test cases 4-10 satisfy no additional constraints.
Problem credits: Benjamin Qi

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Java 解法, 执行用时: 10ms, 内存消耗: 10776K, 提交时间: 2021-07-03 08:27:23

import java.util.*;
import java.io.*;

public class Main {
    
    public static void main(String[] args) throws IOException{
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        
        StringTokenizer st = new StringTokenizer(br.readLine());
        
        int[] inputs = new int[7];
        
        for(int i=0; i<7; i++) {
            inputs[i] = Integer.parseInt(st.nextToken());
        }
        
        Arrays.sort(inputs);
        
        int A = inputs[0];
        int B = inputs[1];
        int C = inputs[6] - A - B;
        
        bw.write(A + " " + B + " " + C + "\n");
        bw.flush();
        
    }
    
}

C++ 解法, 执行用时: 4ms, 内存消耗: 412K, 提交时间: 2021-11-29 14:54:16

#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[7]={0};
	for(int i=0;i<7;i++){
		cin>>a[i]; 
	}
	sort(a,a+7);
	cout<<a[0]<<" "<<a[1]<<" "<<a[6]-a[0]-a[1]<<endl;
}

上一题