ZOJ Problem Set - 3860Find the Spy (STL-> map 建立简单查询表 )

4 篇文章 0 订阅
3 篇文章 0 订阅
这是一个关于ZOJ Problem Set中3860题目的解析,题目要求找出间谍,间谍的ID与其他人不同。给定每个测试用例包含学生数量N和所有学生的32位ID,你需要输出与众不同的ID。示例输入和输出分别展示了不同测试用例的结果,如当N为10时,输出6,当N为3时,输出8,当N为5时,输出2009。该问题可以利用STL中的map建立简单的查询表来解决。
摘要由CSDN通过智能技术生成

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;
}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值