A - 1001

    xiaoxiao2021-03-25  77

    Description

    Whoooa! There is a spy in Marjar University. All we know is that the spy has a special ID card. Please find him out!

    Input

    There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

    The first line contains a integer N (3 ≤ N ≤ 100), which describes that there are N students need to be checked.

    The second line contains N integers indicating the ID card number of N students. All ID card numbers are 32-bit integers.

    Output

    For each test case, output the ID card number which is different from others.

    Sample Input

    3 10 1 1 1 1 1 1 1 1 6 1 3 9 9 8 5 90016 90016 90016 2009 90016

    Sample Output

    6 8 2009

    题意:

    给你一组数据,寻找里面不同的!

    思路:

    运用sort对数据进行排序,不难发现,不同的数字要不然在第一个要不然在最后一个!

    代码:

    #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #include<cmath> using namespace std; int a[105]; int main() { int t,n,i; cin>>t; while(t--) { memset(a,0,sizeof(a)); cin>>n; for(i=0;i<n;i++) cin>>a[i]; sort(a,a+n); if(a[0]==a[1]) cout<<a[n-1]<<endl; else cout<<a[0]<<endl; } return 0; } 心得:

    题目简单, 要善于寻找最简单的解题方法!

    转载请注明原文地址: https://ju.6miu.com/read-16479.html

    最新回复(0)