Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static bool[,] grid;
- private static bool[] tmpRow;
- private static bool[] tmpColumn;
- static void Main(string[] args)
- {
- grid = new bool[50,6];
- tmpRow = new bool[50];
- tmpColumn = new bool[6];
- string[] lines = File.ReadAllLines("C:/input.txt");
- for(int i = 0; i < lines.Length; i++)
- {
- string[] commands = lines[i].Split(' ');
- if (commands[0] == "rect")
- {
- string[] wh = commands[1].Split('x');
- int w = int.Parse(wh[0]);
- int h = int.Parse(wh[1]);
- Rect(w, h);
- }
- else
- {
- if(commands[1] == "row")
- {
- int rowId = int.Parse(commands[2].Split('=')[1]);
- int rcount = int.Parse(commands[4]);
- RotateRow(rowId, rcount);
- }
- else
- {
- int columnId = int.Parse(commands[2].Split('=')[1]);
- int ccount = int.Parse(commands[4]);
- RotateColumn(columnId, ccount);
- }
- }
- }
- int result = 0;
- for(int x = 0; x < 50; x++)
- {
- for(int y = 0; y < 6; y++)
- {
- if(grid[x,y])
- {
- result++;
- }
- }
- }
- Console.WriteLine("Done");
- Console.WriteLine(result);
- Console.ReadKey();
- }
- public static void Rect(int width, int height)
- {
- for(int x = 0; x < width; x++)
- {
- for(int y = 0; y < height; y ++)
- {
- grid[x, y] = true;
- }
- }
- }
- public static void RotateRow(int rowId, int count)
- {
- if(count == 50)
- {
- return;
- }
- count = count % 50;
- int offset = 50 - count;
- for(int i = 0; i <50; i++)
- {
- tmpRow[i] = grid[offset, rowId];
- offset++;
- offset = offset % 50;
- }
- for(int i = 0; i < 50; i++)
- {
- grid[i, rowId] = tmpRow[i];
- }
- }
- public static void RotateColumn(int columnId, int count)
- {
- if (count == 6)
- {
- return;
- }
- count = count % 6;
- int offset = 6 - count;
- for (int i = 0; i < 6; i++)
- {
- tmpColumn[i] = grid[columnId, offset];
- offset++;
- offset = offset % 6;
- }
- for (int i = 0; i < 6; i++)
- {
- grid[columnId, i] = tmpColumn[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement