ZOJ Problem Set - 3860Find the Spy
--------------------------------------------------------------------------------
Time Limit: 2 Seconds Memory Limit: 65536 KB
--------------------------------------------------------------------------------
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
--------------------------------------------------------------------------------
Author: DAI, Longao
Source: The 15th Zhejiang University Programming Contest
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cmath>
//#include<bits/stdc++.h>
#include<map>
using namespace std;
template<class T>inline T read(T&x)
{
char c;
while((c=getchar())<=32)if(c==EOF)return 0;
bool ok=false;
if(c=='-')ok=true,c=getchar();
for(x=0; c>32; c=getchar())
x=x*10+c-'0';
if(ok)x=-x;
return 1;
}
template<class T> inline T read_(T&x,T&y)
{
return read(x)&&read(y);
}
template<class T> inline T read__(T&x,T&y,T&z)
{
return read(x)&&read(y)&&read(z);
}
template<class T> inline void write(T x)
{
if(x<0)putchar('-'),x=-x;
if(x<10)putchar(x+'0');
else write(x/10),putchar(x%10+'0');
}
template<class T>inline void writeln(T x)
{
write(x);
putchar('\n');
}
//-------ZCC IO template------
const int maxn=11;
const double inf=999999999;
#define lson (rt<<1),L,M
#define rson (rt<<1|1),M+1,R
#define M ((L+R)>>1)
#define For(i,t,n) for(int i=(t);i<=(n);i++)
//typedef long long LL;
typedef double DB;
typedef pair<int,int> P;
#define bug printf("---\n");
#define mod 10007
map<int,int> mp;
map<int,int>::iterator it;
int main()
{
//#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
//freopen("zccccc.txt","w",stdout);
//#endif // ONLINE_JUDGE
int n,m,i,j,t,k;
int T;
read(T);
while(T--)
{
read(n);
mp.clear();
while(n--)
{
read(k);
mp[k]++;
}
it=mp.begin();
while(it!=mp.end())
{
if(it->second==1)
{
writeln(it->first);break;
}
it++;
}
}
return 0;
}