In an array of integers, except for two digits, the other numbers appear two times. Please write the program to find the two only occurrences of the number. Experience: At first I thought it was only one occurrence of a number, the problem is that there are 2 only one occurrence of the number//array from i=0, start, another j=i+1 start, when there is an equal I will save it in my newly created array b[n/2+1],//when J==n, Indicates that there is no value equal to a[i after position I, but there is no guarantee that there is no front,//So here I saved the data in the B array to work, and then iterate through the B array, if the B array still does not find the same//number, We get this one-time-only number. You can then save it and then ask for the next one.//the sword means the offer is perfectly passed. #include <iostream>using namespace std;void grial (int a[],int n {int B[n/2+1];int i = 0;int k = 0; for (; i<n;i++) {int J, for (j = i+1; j<n;j++) {if (A[i]==a[j]) {b[k++]=a[i];break;}} int m = 0; if (j>=n) {for (; m<k;m++) {if (a[i]==b[m]) break;}} if (m>=k && j>=n) {cout<<a[i]<<endl;//a[i] is stored in *num1,*num2 is the result of the offer in the Sword.}} int main () {int a[]={1,1,2,3,4,4}; Grial (a,6); return 0;}
C + + to find only one occurrence of two numbers in the array and save (ox-Guest sword refers to offer)