Advertisement
dentia

Na Baba mi smetalnika

Apr 5th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.53 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 Neurons
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             const string LEFT_CMD = "left";
  14.             const string RIGHT_CMD = "right";
  15.             const string RESET_CMD = "reset";
  16.             const string STOP_CMD = "stop";
  17.  
  18.             int width = int.Parse(Console.ReadLine());
  19.             int[,] matrix = new int[8, width];
  20.  
  21.             for (int i = 0; i < 8; i++)
  22.             {
  23.                 long number = long.Parse(Console.ReadLine());
  24.                 for (int j = 0, k = width-1; j < width; j++, k--)
  25.                 {
  26.                     matrix[i, k] = (int)((number >> j) & 1);
  27.                 }
  28.             }
  29.             string command = Console.ReadLine();
  30.             while (command != STOP_CMD)
  31.             {
  32.                 if (command == LEFT_CMD)
  33.                 {
  34.                     int currentY = int.Parse(Console.ReadLine());
  35.                     int currentX = int.Parse(Console.ReadLine());
  36.  
  37.                     if (currentX > width - 1) currentX = width - 1;
  38.  
  39.                     int count = 0;
  40.  
  41.                     for (int i = currentX; i >= 0; i--)
  42.                     {
  43.                         if (matrix[currentY, i] == 1) ++count;
  44.                         matrix[currentY, i] = 0;
  45.                     }
  46.  
  47.                     for (int i = count-1; i>=0 ; i--)
  48.                     {
  49.                         matrix[currentY, i] = 1;
  50.                     }
  51.                 }
  52.                 else if (command == RIGHT_CMD)
  53.                 {
  54.                     int currentY = int.Parse(Console.ReadLine());
  55.                     int currentX = int.Parse(Console.ReadLine());
  56.  
  57.                     if (currentX < 0) currentX = 0;
  58.  
  59.                     int count = 0;
  60.  
  61.                     for (int i = currentX; i < width; i++)
  62.                     {
  63.                         if (matrix[currentY, i] == 1) ++count;
  64.                         matrix[currentY, i] = 0;
  65.                     }
  66.  
  67.                     for (int i = width-count; i < width; i++)
  68.                     {
  69.                         matrix[currentY, i] = 1;
  70.                     }
  71.                 }
  72.                 else if (command == RESET_CMD)
  73.                 {
  74.                     for (int row = 0; row < 8; row++)
  75.                     {
  76.                         int count = 0;
  77.                         for (int col = 0; col < width; col++)
  78.                         {
  79.                             if (matrix[row, col] == 1) ++count;
  80.                             matrix[row, col] = 0;
  81.                         }
  82.  
  83.                         for (int j = 0; j < count; j++)
  84.                         {
  85.                             matrix[row, j] = 1;
  86.                         }
  87.                     }
  88.                 }
  89.  
  90.                 command = Console.ReadLine();
  91.             }
  92.  
  93.             int countFreeCells = 0;
  94.             for (int col = 0; col < width; col++)
  95.             {
  96.                 bool freeCell = true;
  97.                 for (int row = 0; row < 8; row++)
  98.                 {
  99.                     if (matrix[row, col] == 1) freeCell = false;
  100.                 }
  101.                 if (freeCell) ++countFreeCells;
  102.             }
  103.             long sum = 0;
  104.  
  105.             for (int i = 0; i < 8; i++)
  106.             {
  107.                 string str = "";
  108.                 for (int j = 0; j < width; j++)
  109.                 {
  110.                     str += matrix[i, j];
  111.                 }
  112.                 long number = Convert.ToInt64(str, 2);
  113.                 sum += number;
  114.             }
  115.  
  116.             sum *= countFreeCells;
  117.  
  118.             Console.WriteLine(sum);
  119.  
  120.         }
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement