列表

详情


NC25689. Seek Spy

描述

    In order to celebrate the admission of new members, Coach Fang resolves to hold a programme named . Participants include Coach Fang, Boss Niu, God Chai, Brother Wang, Teacher Gao and Senior Wang, six persons in total. Initially all of them will be distributed one card which contains a number. It is known that five of the numbers on their cards are identical, and the rest one is different.
    Now give you six numbers on the cards, please print the different one.

输入描述

    The first line contains an integer number T, the number of test cases.
     of each next T lines contains six integers a, b, c, d, e, f().
            
        

输出描述

For each test case print a number, the number which differs from others.

示例1

输入:

2
3 4 3 3 3 3
6 6 6 5 6 6

输出:

4
5

原站题解

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

C++14(g++5.4) 解法, 执行用时: 4ms, 内存消耗: 488K, 提交时间: 2019-05-12 16:40:19

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

Python3 解法, 执行用时: 41ms, 内存消耗: 4580K, 提交时间: 2022-01-29 11:50:09

from collections import Counter as ctr
for _ in range(int(input())):
    l = ctr(list(map(int, input().split())))
    for i in l:
        if l[i] == 1:
            print(i)

C++11(clang++ 3.9) 解法, 执行用时: 5ms, 内存消耗: 484K, 提交时间: 2019-05-12 13:36:24

#include<bits/stdc++.h>
using namespace std;int a[6];int main(){int t;cin>>t;while(t--){for(int i=0;i<6;i++)cin>>a[i];sort(a,a+6);printf("%d\n",a[2]==a[0]?a[5]:a[0]);}}

上一题