Title Description
Given an array, the remaining number appears 2 times, except for a number that occurs 1 times. Find out the number that appears once.
For example: {1, 2, 1, 2, 1, 2, 7}, find 7.
Enter a description
The first line enters a number n, which represents the length of the array, and the next line enters n integers representing the array a[n].
Output description
The output appears only once in number.
Input sample
4 0 0 5 5 7
Output sample
7
Problem analysis
When all the numbers in the array are different or up, each pair will have a number of 0, and then the last number left is the number that only 1 times.
Test code
1#include <stdio.h>2#include <stdlib.h>3 4 intMainvoid)5 {6 intn, I, *arr;7 8scanf"%d", &n);9Arr = (int*)malloc(n *sizeof(int));Tenscanf"%d", arr); One for(i =1; I < n; i++) A { -scanf"%d", arr +i); -arr[0] ^=Arr[i]; the } -printf"%d\n", arr[0]); - - Free(arr); + return 0; -}
Singal Num (i)