Advertisement
Guest User

Untitled

a guest
Apr 11th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.62 KB | None | 0 0
  1. using System;
  2.  
  3. class NaBabaMiSmetalnika
  4. {
  5.     static void Main()
  6.     {
  7.         int widthSmetalo = int.Parse(Console.ReadLine());
  8.  
  9.         int[,] smetalo = new int[8, widthSmetalo];
  10.         long[] numbers = new long[8];
  11.  
  12.         for (int i = 0; i < 8; i++)
  13.         {
  14.             int mask = int.Parse(Console.ReadLine());
  15.             numbers[i] = mask;
  16.             int move = widthSmetalo - 1;
  17.  
  18.             for (int j = 0; j < widthSmetalo; j++)
  19.             {
  20.                 smetalo[i, j] = (mask >> move) & 1;
  21.                 move--;
  22.             }
  23.         }
  24.  
  25.         //Print the matrix
  26.         //for (int i = 0; i < 8; i++)
  27.         //{
  28.         //    for (int j = 0; j < widthSmetalo; j++)
  29.         //    {
  30.         //        Console.Write(smetalo[i, j]);
  31.         //    }
  32.         //    Console.WriteLine();
  33.         //}
  34.  
  35.         string babaCommand = "";
  36.         int row = 0;
  37.         int prustPosition = 0;
  38.         long result = 0;
  39.         int zeroColumnCounter = 0;
  40.  
  41.         while (true)
  42.         {
  43.             int onesCount = 0;
  44.             int zeroCount = 0;
  45.             zeroColumnCounter = 0;
  46.  
  47.             babaCommand = Console.ReadLine();
  48.             if (babaCommand == "stop")
  49.             {
  50.                 for (int i = 0; i < 8; i++)
  51.                 {
  52.                     numbers[i] = 0;
  53.                     for (int j = 0; j < widthSmetalo; j++)
  54.                     {
  55.                         long temp = 1;
  56.                         numbers[i] <<= 1;
  57.                         if (smetalo[i, j] == 1)
  58.                             numbers[i] = numbers[i] | temp;
  59.                     }
  60.                     result += numbers[i];
  61.                 }
  62.  
  63.  
  64.                 for (int i = widthSmetalo - 1; i >= 0; i--)
  65.                 {
  66.                     zeroCount = 0;
  67.                     for (int j = 0; j < 8; j++)
  68.                     {
  69.                         if (smetalo[j, i] == 0)
  70.                             zeroCount++;
  71.                     }
  72.                     if (zeroCount == 8)
  73.                         zeroColumnCounter++;
  74.                 }
  75.                 break;
  76.             }
  77.             else if (babaCommand == "left" || babaCommand == "right")
  78.             {
  79.                 row = int.Parse(Console.ReadLine());
  80.                 prustPosition = int.Parse(Console.ReadLine());
  81.  
  82.                 if (prustPosition < 0)
  83.                     prustPosition = 0;
  84.                 else if (prustPosition > widthSmetalo - 1)
  85.                     prustPosition = widthSmetalo - 1;
  86.  
  87.                 if (babaCommand == "left")
  88.                 {
  89.                     for (int i = 0; i <= prustPosition; i++)
  90.                     {
  91.                         if (smetalo[row, i] == 1)
  92.                         {
  93.                             onesCount++;
  94.                             smetalo[row, i] = 0;
  95.                         }
  96.                     }
  97.  
  98.                     for (int i = 0; onesCount > 0; i++, onesCount--)
  99.                     {
  100.                         smetalo[row, i] = 1;
  101.                     }
  102.  
  103.  
  104.                 }
  105.                 else if (babaCommand == "right")
  106.                 {
  107.                     for (int i = prustPosition; i < widthSmetalo; i++)
  108.                     {
  109.                         if (smetalo[row, i] == 1)
  110.                         {
  111.                             onesCount++;
  112.                             smetalo[row, i] = 0;
  113.                         }
  114.                     }
  115.  
  116.                     for (int i = widthSmetalo - 1; onesCount > 0; i--, onesCount--)
  117.                     {
  118.                         smetalo[row, i] = 1;
  119.                     }
  120.                 }
  121.                
  122.             }
  123.             else if (babaCommand == "reset")
  124.             {
  125.                 for (int i = 0; i < 8; i++)
  126.                 {
  127.                     onesCount = 0;
  128.                     for (int j = 0; j < widthSmetalo; j++)
  129.                     {
  130.                         if (smetalo[i, j] == 1)
  131.                         {
  132.                             onesCount++;
  133.                             smetalo[i, j] = 0;
  134.                         }
  135.                     }
  136.  
  137.                     for (int j = 0; onesCount > 0; j++, onesCount--)
  138.                     {
  139.                         smetalo[i, j] = 1;
  140.                     }
  141.                 }
  142.             }
  143.             //for (int i = 0; i < 8; i++)
  144.             //{
  145.             //    for (int j = 0; j < widthSmetalo; j++)
  146.             //    {
  147.             //        Console.Write(smetalo[i, j]);
  148.             //    }
  149.             //    Console.WriteLine();
  150.             //}
  151.         }
  152.         Console.WriteLine(result * zeroColumnCounter);
  153.     }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement