Description
给定些数字,这些数中只有一个数出现了奇数次,找出这个数。
Input
每组数据第一行n表示数字个数,1 <= n <= 2 ^ 18 且 n % 2 == 1。
接下来n行每行一个32位有符号整数。
Output
出现奇数次那个数,每组数据对应一行。
Sample Input
5 1 1 2 2 3 7 1 2 1 2 2 3 3
Sample Output
3 2
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
int n,a;
while(cin>>n){
int t=0;
for(int i=0;i<n;i++){
cin>>a;
t^=a;
}
cout<<t<<endl;
}
}
本文介绍了一种通过异或操作高效查找数组中唯一出现奇数次的整数的方法。输入为一系列整数,其中仅有一个整数出现奇数次,其余整数均成对出现。文章提供了完整的C++代码实现,利用异或性质巧妙地解决了问题。
888

被折叠的 条评论
为什么被折叠?



