svetlozar_kirkov

Bit Paths (100/100)

Oct 28th, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace BitPaths
  5. {
  6.     class BitPaths
  7.     {
  8.         static void Main()
  9.         {
  10.             int paths = int.Parse(Console.ReadLine());
  11.             string[] pathsArray = new string[paths];
  12.             for (int i = 0; i < pathsArray.Length; i++)
  13.             {
  14.                 pathsArray[i] = Console.ReadLine();
  15.             }
  16.             int[,] board = new int[8,4];
  17.  
  18.             for (int i = 0; i < pathsArray.Length; i++)
  19.             {
  20.                 string[] tempPath = pathsArray[i].Split(',');
  21.                 int initial = Convert.ToInt32(tempPath[0].ToString());
  22.                 int currentCol = initial;
  23.                
  24.                 if (board[0,initial]==1)
  25.                 {
  26.                     board[0, initial] = 0;
  27.                 }
  28.                 else
  29.                 {
  30.                     board[0, initial] = 1;
  31.                 }
  32.                 for (int j = 0, k = 1; j < 7; j++,k++)
  33.                 {
  34.                     if (tempPath[k] == "-1")
  35.                     {
  36.                         currentCol = currentCol-1;
  37.                     }
  38.                     else if (tempPath[k] == "+1")
  39.                     {
  40.                         currentCol = currentCol + 1;
  41.                     }
  42.                     if (board[k, currentCol] == 1)
  43.                     {
  44.                         board[k, currentCol] = 0;
  45.                     }
  46.                     else
  47.                     {
  48.                         board[k, currentCol] = 1;
  49.                     }
  50.                 }
  51.             }
  52.  
  53.             List<string> binaries = new List<string>();
  54.  
  55.             for (int i = 0; i < 8; i++)
  56.             {
  57.                 string[] temp = new string[4];
  58.                
  59.                 for (int j = 0; j < 4; j++)
  60.                 {
  61.                     temp[j] = board[i, j].ToString();
  62.                 }
  63.                 string joined = string.Join("", temp);
  64.                 binaries.Add(joined);
  65.             }
  66.  
  67.             int sum = 0;
  68.             foreach (var binary in binaries)
  69.             {
  70.                 sum += Convert.ToInt32(binary, 2);
  71.             }
  72.             Console.WriteLine(Convert.ToString(sum,2));
  73.             Console.WriteLine(sum.ToString("X"));
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment