stkirov

Problem 4 – Odd Number

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