Advertisement
Filkolev

[Exam Preparation] 05. Bit Paths - char array

Nov 3rd, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. using System;
  2.  
  3. class BitPathsStrings
  4. {
  5.     static void Main()
  6.     {
  7.         byte count = byte.Parse(Console.ReadLine());
  8.  
  9.         char[][] board = new char[8][];
  10.  
  11.         for (byte row = 0; row < 8; row++)
  12.         {
  13.             board[row] = new char[] {'0', '0', '0', '0'};          
  14.         }
  15.  
  16.         for (byte i = 0; i < count; i++)
  17.         {
  18.             sbyte[] path = new sbyte[8];
  19.  
  20.             string[] input = Console.ReadLine().Split(',');
  21.  
  22.             for (byte num = 0; num < 8; num++)
  23.             {
  24.                 path[num] = sbyte.Parse(input[num]);
  25.             }
  26.  
  27.             sbyte position = 0;
  28.  
  29.             for (byte row = 0; row < 8; row++)
  30.             {
  31.                 position += path[row];
  32.  
  33.                 if (board[row][position] == '0')
  34.                 {
  35.                     board[row][position] = '1';
  36.                 }
  37.                 else
  38.                 {
  39.                     board[row][position] = '0';
  40.                 }
  41.             }
  42.         }
  43.  
  44.         byte sum = 0;
  45.  
  46.         for (byte i = 0; i < 8; i++)
  47.         {
  48.             sum += Convert.ToByte(new string(board[i]), 2);
  49.         }
  50.  
  51.         Console.WriteLine(Convert.ToString(sum, 2));
  52.         Console.WriteLine("{0:X}", sum);
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement