0
点赞
收藏
分享

微信扫一扫

哈尔滨理工大学第六届程序设计团队赛—C


problem C.ID

TimeLimit: 1000ms  Memory Limit: 100000k

Description

It is very cold in Harbin in thewinter, but it is pretty warm in the Zhengxin Building. Today is Saturday,Teacher ABG want to play a trick on the only one student called NWL because hedidn’t finish the MOOC.

At the beginning, every student isin the building. The teacher calls some students to sweep the snow on theplayground out of the building, and sometimes he also call some students whoare on the playground back to the building. At last, teacher ABG wants to leaveonly one student, NWL, on the playground out of the building. It means that theteacher ABG calls NWL’s ID ODD times, but called other students’ ID EVEN times,maybe more than twice. Now give you the list describing the students’ ID whichthe teacher called in order, please tell us NWL’s ID.

Input

The first line is an integer T,describes the number of tests. Then T tests.

In each test, the first line is aninteger N, describes the number of IDs on the list.

Then followed N lines, each linecontains an integer M, describes one ID on the list.

Output

T lines. Each line, an integer,the NWL’s ID

Sample

Input

Output

3

3

1140310000

1140310000

1140310000

1

1140310002

5

1

2

2

2

2

1140310000

1140310002

1

 

 

Hint

1<=T<=10

1<=N<=1,000,000

1<=M<=1,159,999,999

The sum of N in the input file isno more than 3,000,000, all the input are integers and correct.

 【分析】

其实不难,异或,或者用map<int,int>标记算答案也可以。

当然最简单的肯定是异或了,因为除了目标出现的次数是奇数,其他学生出现的次数都是偶数,而两个一样的数异或结果为0.

所以整个数组异或一遍,剩下的那个数就是目标了。

【代码】


#include <stdio.h>
int main()
{
int pp;scanf("%d",&pp);
while (pp--)
{
int n;scanf("%d",&n);
long long ans=0;
for (int i=0;i<n;i++)
{
long long x;scanf("%lld",&x);
ans^=x;
}
printf("%lld\n",ans);
}
return 0;
}



举报

相关推荐

0 条评论