Advertisement
sashomaga

Odd Number

Dec 26th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System;
  2.  
  3. //You are given a list of N integer numbers all but one of which appears an even number of times.
  4. //Write a program to find the one integer which appears an odd number of times.
  5. //Input
  6. //The input data is being read from the console.
  7. //The number N is written on the first input line.
  8. //On each of the following N lines there is one integer number written – the consequent number from the given list of numbers.
  9. //The input data will always be valid and in the format described. There is no need to check it explicitly.
  10. //Output
  11. //The output data must be printed on the console.
  12. //On the only output line you must print the integer from the list which appears an odd number of times.
  13. //Constraints
  14. //•   N will be positive odd integer number between 1 and 99 999, inclusive.
  15. //•   All of the numbers in the list will be integer numbers between -9 223 372 036 854 775 808
  16. //and 9 223 372 036 854 775 807, inclusive.
  17.  
  18.  
  19. class Program
  20. {
  21.     static void Main()
  22.     {
  23.         int n = int.Parse(Console.ReadLine());
  24.         long answer = 0;
  25.         long num;
  26.         for (int i = 0; i < n; i++)
  27.         {
  28.             num = long.Parse(Console.ReadLine());
  29.             answer ^= num;
  30.         }
  31.         Console.WriteLine(answer);
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement