#C6906. Find the Integer with Odd Occurrence
Find the Integer with Odd Occurrence
Find the Integer with Odd Occurrence
You are given a series of test cases. In each test case, an array of integers is provided such that every integer appears an even number of times except for one that appears an odd number of times. Your task is to identify and output this unique integer.
The solution can be derived using properties of the bitwise XOR operator. Recall that for any integer \(a\), we have \(a \oplus a = 0\) and \(a \oplus 0 = a\). Therefore, performing XOR on all numbers in the test case will cancel out all numbers that occur an even number of times, leaving only the target integer.
inputFormat
The input is read from stdin
and consists of multiple test cases. The first line contains an integer \(T\) specifying the number of test cases. Each of the next \(T\) lines contains a test case with space-separated integers.
outputFormat
For each test case, output the integer that occurs an odd number of times on a new line, writing the result to stdout
.
2
1 2 3 2 3 1 3
4 5 6 5 6 4 4
3
4
</p>