Advertisement
elena1234

OddTimesWith ^ operator

Oct 4th, 2020 (edited)
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace OddTimes
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             int[] numbers = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.             int result = numbers[0];
  13.  
  14.             for (int i = 1; i < numbers.Length; i++)
  15.             {
  16.                 result = result ^ numbers[i];
  17.             }
  18.  
  19.             Console.WriteLine(result);
  20.  
  21.             //example with first input:result=numbers[0]=1=001; result=010^001=011; result=011^011=000; 010^000=010; 011^010=001; 001^001=000; result=011^000=011=3;
  22.  
  23.         }
  24.     }
  25. }
  26.  
  27.  
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement