Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class BitLock
- {
- static void Main()
- {
- int[,] matrix = new int[8,12];
- string inputNums = Console.ReadLine();
- int[] nums = inputNums.Split(' ').Select(n => Convert.ToInt32(n)).ToArray();
- List<int> countChecker = new List<int>();
- for (int i = 0; i < matrix.GetLongLength(0); i++)
- {
- for (int j = (int)matrix.GetLongLength(1)-1,k = 1; j >=0; j--,k*=2)
- {
- matrix[i, j] = ToBinary(nums[i]/k);
- }
- }
- bool notEnd = true;
- while(notEnd)
- {
- string inputOrders = Console.ReadLine();
- string[] orders = inputOrders.Split().ToArray();
- if (orders.Length == 3)
- {
- matrix = Rotate(orders,matrix);
- }
- if (orders.Length == 2)
- {
- countChecker.Add(Check(orders, matrix));
- }
- else if(orders.Length == 1)
- {
- notEnd = false;
- }
- }
- // Toint
- List<int> outputNums = new List<int>();
- for (int i = 0; i < matrix.GetLongLength(0); i++)
- {
- int number = 0;
- for (int j = 0, k = (int)matrix.GetLongLength(1)-1 ; j < matrix.GetLongLength(1); j++,k--)
- {
- number +=matrix[i, j] *((int) Math.Pow(2, k));
- }
- outputNums.Add(number);
- }
- Print(countChecker, outputNums);
- }
- static int ToBinary(int num)
- {
- int bit = 0;
- bit = num % 2;
- return bit;
- }
- static int Check(string[] orders,int[,] matrix)
- {
- int col = int.Parse(orders[1]);
- col = 12 - (col+1);
- int counter = 0;
- for (int i = 0; i < matrix.GetLongLength(0); i++)
- {
- if (matrix[i,col] == 1)
- {
- counter++;
- }
- }
- return counter;
- }
- static int[,] Rotate(string[] orders,int[,] matrix)
- {
- int row = int.Parse(orders[0]);
- string direction = orders[1];
- int rotations = int.Parse(orders[2]);
- if (direction == "right")
- {
- for (int j = 0; j < rotations; j++)
- {
- int last = (int)matrix.GetLongLength(1) - 1;
- for (var i = 0; i < last; i ++)
- {
- matrix[row, i] ^= matrix[row, last];
- matrix[row, last] ^= matrix[row, i];
- matrix[row, i] ^= matrix[row, last];
- }
- }
- }
- else if(direction == "left")
- {
- for (int j = 0; j < rotations; j++)
- {
- int last = (int)matrix.GetLongLength(1) - 1;
- for (var i = last-1; i >= 0; i--)
- {
- matrix[row, i] ^= matrix[row, last];
- matrix[row,last] ^= matrix[row, i];
- matrix[row, i] ^= matrix[row, last];
- }
- }
- }
- return matrix;
- }
- static void Print(List<int> countChecker, List<int> outputNums)
- {
- foreach (var nums in countChecker)
- {
- Console.WriteLine(nums);
- }
- foreach (var number in outputNums)
- {
- Console.Write(number + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement