Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Numerics;
- class NaBabaMiSmetalnika
- {
- static void ResetMatrix(int[,] matrix, int width)
- {
- int countOnes = 0;
- for (int i = 0; i < 8; i++)
- {
- for (int j = 0; j < width; j++)
- {
- if (matrix[i, j] == 1)
- {
- countOnes++;
- matrix[i, j] = 0;
- }
- }
- for (int j = 0; j < countOnes; j++)
- {
- matrix[i, j] = 1;
- }
- countOnes = 0;
- }
- }
- static void FingerLeft(int[,] matrix, int width, int row, int col)
- {
- if (col < 0)
- col = 0;
- if (col > width - 1)
- col = width - 1;
- int countOnes = 0;
- for (int j = 0; j <= col; j++)
- {
- if (matrix[row, j] == 1)
- {
- countOnes++;
- matrix[row, j] = 0;
- }
- }
- for (int j = 0; j < countOnes; j++)
- {
- matrix[row, j] = 1;
- }
- }
- static void FingerRight(int[,] matrix, int width, int row, int col)
- {
- if (col < 0)
- col = 0;
- if (col > width - 1)
- col = width - 1;
- int countOnes = 0;
- for (int j = width - 1; j >= col; j--)
- {
- if (matrix[row, j] == 1)
- {
- countOnes++;
- matrix[row, j] = 0;
- }
- }
- for (int j = width - 1; j >= width - countOnes; j--)
- {
- matrix[row, j] = 1;
- }
- }
- static BigInteger CheckEmptyCols(int[,] matrix, int width)
- {
- bool empty = true;
- BigInteger result = 0;
- for (int j = 0; j < width; j++)
- {
- for (int i = 0; i < 8; i++)
- {
- if (matrix[i, j] == 1)
- {
- empty = false;
- break;
- }
- }
- if (empty)
- {
- result++;
- }
- else
- {
- empty = true;
- }
- }
- return result;
- }
- static BigInteger SumLines(int[,] matrix, int width)
- {
- BigInteger sumOfLines = 0;
- string bild = "";
- for (int i = 0; i < 8; i++)
- {
- for (int j = 0; j < width; j++)
- {
- bild += matrix[i, j];
- }
- sumOfLines += (Convert.ToInt64(bild, 2));
- bild = "";
- }
- return sumOfLines;
- }
- static void Main()
- {
- int width = Int32.Parse(Console.ReadLine());
- int[,] abacus = new int[8, width];
- //fill abacus field
- string[] arr = new string[8];
- for (int i = 0; i < 8; i++)
- {
- arr[i] = Convert.ToString(int.Parse(Console.ReadLine()), 2).PadLeft(width, '0');
- for (int j = 0; j < width; j++)
- {
- abacus[i, j] = arr[i][j] == '0' ? 0 : 1;
- }
- }
- while (true)
- {
- pointer:
- string command = Console.ReadLine();
- if (command == "stop")
- break;
- if (command == "reset")
- {
- ResetMatrix(abacus, width);
- goto pointer;
- }
- int fingerRow = Int32.Parse(Console.ReadLine());
- int fingerCol = Int32.Parse(Console.ReadLine());
- if (command == "right")
- FingerRight(abacus, width, fingerRow, fingerCol);
- if (command == "left")
- FingerLeft(abacus, width, fingerRow, fingerCol);
- }
- //print result
- Console.WriteLine(CheckEmptyCols(abacus, width) * SumLines(abacus, width));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement