Advertisement
Guest User

Untitled

a guest
Dec 6th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _05_BitTower
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //input and fill the matrix
  14.             string[] numbers = new string[8];
  15.             for (int i = 0; i < 8; i++)
  16.             {
  17.                 int input = int.Parse(Console.ReadLine());
  18.                 numbers[i] = Convert.ToString(input, 2).PadLeft(8, '0');
  19.             }
  20.  
  21.             char[,] field = new char[8, 8];
  22.             for (int row = 7; row >= 0; row--)
  23.             {
  24.                 for (int col = 0; col < 8; col++)
  25.                 {
  26.                     field[row, col] = numbers[row][col];
  27.                 }
  28.             }
  29.  
  30.             int enteredKnights = 0;
  31.             for (int row = 0; row < 8; row++)
  32.             {
  33.                 for (int col = 0; col < 8; col++)
  34.                 {
  35.                     if (field[row, col] == '1')
  36.                     {
  37.                         enteredKnights++;
  38.                     }
  39.                 }
  40.             }
  41.  
  42.             int survivors = 0;
  43.             while (true)
  44.             {
  45.                 string command = Console.ReadLine();
  46.                 if (command == "select")
  47.                 {
  48.                     int selectFloor = int.Parse(Console.ReadLine());
  49.                     int selectPosition = int.Parse(Console.ReadLine());
  50.                     field[selectFloor, selectPosition] = '0';
  51.                 }
  52.  
  53.                 else if (command == "kill")
  54.                 {
  55.                     int killFloor = int.Parse(Console.ReadLine());
  56.                     int killPosition = int.Parse(Console.ReadLine());
  57.  
  58.                     if (killPosition == 0)
  59.                     {
  60.                         if (field[killFloor, killPosition] == '1')
  61.                         {
  62.  
  63.                         }
  64.  
  65.                         else if (field[killFloor, killPosition + 1] == '1')
  66.                         {
  67.                             field[killFloor, killPosition + 1] = '0';
  68.                         }
  69.                     }
  70.  
  71.                     else if (killPosition == 7)
  72.                     {
  73.                         if (field[killFloor, killPosition] == '1')
  74.                         {
  75.  
  76.                         }
  77.  
  78.                         else if (field[killFloor, killPosition - 1] == '1')
  79.                         {
  80.                             field[killFloor, killPosition - 1] = '0';
  81.                         }
  82.                     }
  83.  
  84.                     else if ((killPosition < 0 || killPosition > 7) && killFloor <= 1)
  85.                     {
  86.                         survivors++;
  87.                     }
  88.  
  89.                     else if (killPosition > 0 && killPosition < 7)
  90.                     {
  91.                         if (field[killFloor, killPosition] == '1')
  92.                         {
  93.  
  94.                         }
  95.  
  96.                         else if (field[killFloor, killPosition - 1] == '1' && field[killFloor, killPosition + 1] == '0')
  97.                         {
  98.                             field[killFloor, killPosition - 1] = '0';
  99.                         }
  100.  
  101.                         else if (field[killFloor, killPosition + 1] == '1' && field[killFloor, killPosition - 1] == '0')
  102.                         {
  103.                             field[killFloor, killPosition + 1] = '0';
  104.                         }
  105.  
  106.                         else if ((field[killFloor, killPosition + 1] == '1') && (field[killFloor, killPosition + 1] == '1'))
  107.                         {
  108.  
  109.                         }
  110.  
  111.                         else if (field[killFloor, killPosition] == '0')
  112.                         {
  113.                             field[killFloor, killPosition] = '1';
  114.                         }
  115.                     }
  116.                 }
  117.  
  118.                 else if (command == "move")
  119.                 {
  120.                     int moveFloor = int.Parse(Console.ReadLine());
  121.                     int movePosition = int.Parse(Console.ReadLine());
  122.  
  123.                     if (movePosition == 0 && movePosition + 1 == '0')
  124.                     {
  125.                         field[moveFloor, movePosition] = '1';
  126.                     }
  127.  
  128.                     else if (movePosition == 7 && movePosition - 1 == '0')
  129.                     {
  130.                         field[moveFloor, movePosition] = '1';
  131.                     }
  132.  
  133.                     else if ((movePosition < 0 || movePosition > 7) && moveFloor <= 1)
  134.                     {
  135.                         survivors++;
  136.                     }
  137.                 }
  138.                 else if (command == "end")
  139.                 {
  140.                     break;
  141.                 }
  142.             }
  143.  
  144.             for (int row = 0; row < 8; row++)
  145.             {
  146.                 for (int col = 0; col < 8; col++)
  147.                 {
  148.                     if (field[row, col] == '1')
  149.                     {
  150.                         survivors++;
  151.                     }
  152.                 }
  153.             }
  154.  
  155.             string[] newNumbers = new string[8];
  156.  
  157.             for (int row = 0; row < 8; row++)
  158.             {
  159.                 for (int col = 0; col < 8; col++)
  160.                 {
  161.                     newNumbers[row] += field[row, col];
  162.                 }
  163.             }
  164.  
  165.             int sumOfAllInts = 0;
  166.             for (int i = 0; i < 8; i++)
  167.             {
  168.                 int currentNumber = Convert.ToInt32(newNumbers[i], 2);
  169.                 sumOfAllInts += currentNumber;
  170.             }
  171.  
  172.             Console.WriteLine(enteredKnights);
  173.             Console.WriteLine(survivors);
  174.             Console.WriteLine(sumOfAllInts);
  175.  
  176.             //printing
  177.             //for (int row = 0; row < 8; row++)
  178.             //{
  179.             //    for (int col = 0; col < 8; col++)
  180.             //    {
  181.             //        Console.Write(field[row, col]);
  182.             //    }
  183.             //    Console.WriteLine();
  184.             //}
  185.  
  186.            
  187.  
  188.  
  189.         }
  190.     }
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement