A number appears once #include<iostream>using namespace std;int once (Int* a, int num) { int ret = 0; for (int i = 0; i < num; ++i ) { ret ^= a[i]; } return ret;} Int main () { int array[5] = { 1, 2, 2, 3, 3 }; int sum = once (array, 5); cout << sum << endl; return 0;} Two appear once #include <iostream>using namespace std;int two (Int num) { int get = 0; while (num) { if (num % 2 == 1)// Returns the number of digits of the first one that appears in the binary { return get; } get++; num /= 2; } return -1;} Void find (int*a, int ret, int *p, int *q) { int find = 0 ; int pos = 0; for (int i = 0; i < ret; ++i ) { find ^= a[i]; } pos = two (Find); for (int i = 0; i < ret; ++i) { if (1 & (a[i] >> pos)) { *p ^= a[i]; } else { *q ^= a[i]; } }}int main () { int a[8] = { 1, 1, 2, 5, 3, 3, 4, 5 }; int ret = sizeof (a) / sizeof (a[0]); int num1 = 0; int num2 = 0; Find (A,&NBSP;RET,&NBSP;&NUM1,&NBSP;&NUM2); cout << num1 << "," << num2 << endl; return 0;}
Only one and two digits in an array appear once, and the remaining pairs appear