Advertisement
Guest User

05

a guest
Jul 25th, 2014
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         int n = int.Parse(Console.ReadLine());
  8.         int[,] board = new int[8, 4];
  9.         int sum = 0;
  10.  
  11.         for (int i = 0; i < n; i++)
  12.         {
  13.             string[] directions = Console.ReadLine().Split(',');
  14.             int position =  Convert.ToInt32(directions[0]);
  15.  
  16.             if(board[0, position] == 0)
  17.             {
  18.                 board[0, position] = 1;
  19.             }
  20.             else
  21.             {
  22.                 board[0, position] = 0;
  23.             }
  24.  
  25.             for (int j = 1; j < 8; j++)
  26.             {
  27.                 if (directions[j].Trim() == "-1")
  28.                 {
  29.                     position--;
  30.  
  31.                     if(board[j, position] == 0)
  32.                     {
  33.                         board[j, position] = 1;
  34.                     }
  35.                     else if (board[j, position] == 1)
  36.                     {
  37.                         board[j, position] = 0;
  38.                     }
  39.                 }
  40.                 else if (directions[j].Trim() == "0")
  41.                 {
  42.                     if (board[j, position] == 0)
  43.                     {
  44.                         board[j, position] = 1;
  45.                     }
  46.                     else if (board[j, position] == 1)
  47.                     {
  48.                         board[j, position] = 0;
  49.                     }
  50.                 }
  51.                 else if (directions[j].Trim() == "+1")
  52.                 {
  53.                     position++;
  54.  
  55.                     if (board[j, position] == 0)
  56.                     {
  57.                         board[j, position] = 1;
  58.                     }
  59.                     else if (board[j, position] == 1)
  60.                     {
  61.                         board[j, position] = 0;
  62.                     }
  63.                 }
  64.             }
  65.         }
  66.  
  67.         for (int i = 0; i < 8; i++)
  68.         {
  69.             string rowBinary = "";
  70.  
  71.             for (int j = 0; j < 4; j++)
  72.             {
  73.                 rowBinary += board[i, j].ToString();
  74.             }
  75.  
  76.             sum += Convert.ToInt32(rowBinary, 2);
  77.         }
  78.  
  79.         Console.WriteLine(Convert.ToString(sum, 2));
  80.         Console.WriteLine(Convert.ToString(sum, 16).ToUpper());
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement