#include <iostream>using namespace STD;//Place the specified position at 0 or 1. intGrial (intXintNintFlags) {if(Flags = =0) {x &= (~ (0x1<< (N-1))); }Else{x |= (0x1<< (N-1)); }returnx;}intMain () {cout<< Grial ( the,5,1);return 0;}
#include <iostream>using namespace STD;//pairs appear in the array to find the only one that appears only once in the number. //Bitwise XOR or dissimilarity is 1, same as 0. intGrial (intA[],intN) {intIintCount =0; for(i=0; i<n;i++) {count ^= a[i]; }returnCount;}intMain () {intA[] = {1,1,6,3,3,8,8,6,Ten};cout<< Grial (A,9) <<endl;return 0;}
#include <iostream>using namespace Std;//Precipitant two non-repeating numbers that occur only once in the array that appears. int Index(intX//Ask for the first occurrence of the 1 subscript position. {int Count=0; while(x) {Count++;if(X &0x1==1) {return Count; } x >>=1; }}bool Test (intXintY//Determine if the specified y-bit is 1. {return((X & (0x1<< (y1)))) !=0;}voidGrial (intA[],intN) {inti =0;int Count=0;intnumber1=0;//stores the first number. intNumber2=0;//stores the second number. int*adata =New int[n];int*bdata =New int[n];intK1 =0;intK2 =0; for(; i < n; i++) {Count^= A[i]; } i =Index(Count); for(intj =0; J < N; J + +)//The array is divided into two parts here. {if(Test (A[j], i) = =true) {adata[k1++] = a[j]; }Else{bdata[k2++] = a[j]; } } for(i =0; i < K1; i++) {number1 ^= adata[i]; } for(i =0; I < K2; i++) {number2 ^= bdata[i]; } cout << number1 << Endl; cout << number2 << Endl;}intMain () {intA[] = {4,4,6, the,8,3,8,3,6,1070}; Grial (A,Ten);return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C + + Pen test first wave