Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //You are given a list of N integer numbers all but one of which appears an even number of times.
- //Write a program to find the one integer which appears an odd number of times.
- //Input
- //The input data is being read from the console.
- //The number N is written on the first input line.
- //On each of the following N lines there is one integer number written – the consequent number from the given list of numbers.
- //The input data will always be valid and in the format described. There is no need to check it explicitly.
- //Output
- //The output data must be printed on the console.
- //On the only output line you must print the integer from the list which appears an odd number of times.
- //Constraints
- //• N will be positive odd integer number between 1 and 99 999, inclusive.
- //• All of the numbers in the list will be integer numbers between -9 223 372 036 854 775 808
- //and 9 223 372 036 854 775 807, inclusive.
- //• Always only one answer will exists and will be unambiguous.
- //• Allowed working time for your program: 0.25 seconds.
- //• Allowed memory: 16 MB.
- using System;
- class Program
- {
- static void Main()
- {
- string input = Console.ReadLine();
- int N = int.Parse(input);
- long number = 0;
- long result = 0;
- if (N == 1)
- {
- input = Console.ReadLine();
- number = long.Parse(input);
- Console.WriteLine(number);
- }
- else
- {
- for (int i = 0; i < N; i++)
- {
- input = Console.ReadLine();
- number = long.Parse(input);
- result ^= number;
- }
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment