ID 在很多数中间出现次数为奇数的数
来源:互联网 发布:js点击屏幕 隐藏div 编辑:程序博客网 时间:2024/04/28 09:20
It is very cold in Harbin in the winter, 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 he didn’t finish the MOOC.
At the beginning, every student is in the building. The teacher calls some students to sweep the snow on the playground out of the building, and sometimes he also call some students who are on the playground back to the building. At last, teacher ABG wants to leave only one student, NWL, on the playground out of the building. It means that the teacher 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 which the teacher called in order, please tell us NWL’s ID.
InputThe first line is an integer T, describes the number of tests. Then T tests.
In each test, the first line is an integer N, describes the number of IDs on the list.
Then followed N lines, each line contains an integer M, describes one ID on the list.
OutputT lines. Each line, an integer, the NWL’s ID.
Sample Input3311403100001140310000114031000011140310002512222
Sample Output114031000011403100021
Hint1<=T<=10
1<=N<=1,000,000
1<=M<=1,159,999,999
说给你很多数,让你找出出现次数为奇数的那个数,而且已经告诉你只有一个人数出现的次数为奇数。
将输入的所有数字异或起来(^)就是答案。因为a^a=0 , 0^a=a
#include<iostream>
#include<cstdio>
#include<ctime>
#include<cstdlib>
using namespace std;
int m,t;
int n;
int ans;
int main()
{
scanf("%d",&t);
while(t--){
ans=0;
scanf("%d",&m);
for(int i=1;i<=m;i++)
{
scanf("%d",&n);
ans^=n;
}
cout<<ans<<'\n';
}
return 0;
}
- ID 在很多数中间出现次数为奇数的数
- 判断一个序列中出现次数为奇数的数
- 寻找一个数组中出现次数为奇数次的一个数
- 在N个数中找出出现奇数次的数
- 在时间复杂度为 O(n) 内找出数组中出现次数超过一半的数
- 在其它数都出现偶数次的数组中寻找出现奇数次的数
- 在其他数都出现偶数次的数组中找到出现奇数次的数
- 出现次数最多的数
- 出现次数最多的数
- 出现次数最多的数
- 出现次数最多的数
- 出现次数最多的数
- 出现次数最多的数
- 出现次数最多的数
- 出现次数最多的数
- 出现次数最多的数
- 出现次数最多的数
- 出现次数最多的数
- android 上传图片到服务器端
- 过一遍HTML标签(三)
- Dlib人脸特征点检测性能测试(光照+各部分功能模块运行时间)
- ExtJS 6.2 GPL 及离线文档下载地址
- Struts2中的验证
- ID 在很多数中间出现次数为奇数的数
- NVIDIA官方提供的OpenCL实例在Ubuntu14.04编译遇到的问题
- caffe ubuntu16.04 cuda8.0 cudnnv4
- Spring笔记(第二弹:搭建第一个Spring工程)
- order by 1 与 order by 列名
- 英语口语收集(三十)
- 英语口语收集(三十一)
- 【设计模式 - 17】之中介者模式(Mediator)
- 重复元素全排列