Advertisement
Svetli0o

Neurons

Apr 11th, 2014
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         List<uint> list = new List<uint>();
  9.         while (true)
  10.         {
  11.             string tmp = Console.ReadLine();
  12.             if (tmp == "-1")
  13.             {
  14.                 break;
  15.             }
  16.             uint n = uint.Parse(tmp);
  17.             list.Add(n);
  18.         }
  19.         for (int i = 0; i < list.Count; i++)
  20.         {
  21.             if (list[i] == 0)
  22.             {
  23.                 continue;
  24.             }
  25.             char[] numbers = Convert.ToString(list[i], 2).PadLeft(32,'0').ToCharArray();
  26.             int startOne = Array.IndexOf(numbers, '1');
  27.             int lastOne = Array.LastIndexOf(numbers, '1');
  28.             for (int j = startOne; j <= lastOne; j++)
  29.             {                
  30.                 if (numbers[j] == '1')
  31.                 {
  32.                     numbers[j] = '0';
  33.                 }
  34.                 else if (numbers[j] == '0')
  35.                 {
  36.                     numbers[j] = '1';
  37.                 }
  38.             }
  39.             string finalResult = new string(numbers);
  40.             list[i] = Convert.ToUInt32(finalResult, 2);
  41.         }
  42.         foreach (var item in list)
  43.         {
  44.             Console.WriteLine(item);
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement