Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Present_Delivery
- {
- class Program
- {
- static void Main(string[] args)
- {
- int presents = int.Parse(Console.ReadLine());
- int n = int.Parse(Console.ReadLine());
- int rows = n;
- int cols = n;
- char[,] table = new char[rows, cols];
- int sRow = 0;
- int sCol = 0;
- int niceKidsWithPresents = 0;
- for (int row = 0; row < rows; row++)
- {
- char[] currentRow = Console.ReadLine().ToCharArray();
- for (int col = 0; col < cols; col++)
- {
- table[row, col] = currentRow[col];
- if (table[row, col] == 'S')
- {
- sRow = row;
- sCol = col;
- }
- }
- }
- string command = Console.ReadLine();
- while (command!= "Christmas morning" || presents > 0)
- {
- //If the cell has 'X' on it, that means there lives a naughty kid.
- //if a nice kid lives there, the cell is marked by 'V'.
- //marked with 'C' for cookies.
- //All of the empty positions will be marked with '-'.
- switch (command)
- {
- case "up":
- table[sRow, sCol] = '-';
- sRow -= 1;
- if (sRow < 0)
- {
- sRow = rows - 1;
- }
- if (table[sRow, sCol] == 'C')
- {
- table[sRow, sCol] = 'S';
- if (table[sRow + 1, sCol] == 'V' || table[sRow + 1, sCol] == 'X')
- {
- if (table[sRow + 1, sCol] == 'V')
- {
- niceKidsWithPresents++;
- }
- presents--;
- }
- if (table[sRow - 1, sCol] == 'V' || table[sRow - 1, sCol] == 'X')
- {
- if (table[sRow + 1, sCol] == 'V')
- {
- niceKidsWithPresents++;
- }
- presents--;
- }
- if (table[sRow, sCol + 1] == 'V' || table[sRow, sCol + 1] == 'X')
- {
- if (table[sRow + 1, sCol] == 'V')
- {
- niceKidsWithPresents++;
- }
- presents--;
- }
- if (table[sRow + 1, sCol - 1] == 'V' || table[sRow + 1, sCol - 1] == 'X')
- {
- if (table[sRow + 1, sCol] == 'V')
- {
- niceKidsWithPresents++;
- }
- presents--;
- }
- }
- if (table[sRow,sCol] == 'V')
- {
- niceKidsWithPresents++;
- presents --;
- table[sRow, sCol] = 'S';
- }
- if (table[sRow, sCol] == 'X')
- {
- table[sRow, sCol] = 'S';
- }
- break;
- case "down":
- table[sRow, sCol] = '-';
- sRow += 1;
- if (sRow > rows-1)
- {
- sRow = 0;
- }
- if (table[sRow, sCol] == 'C')
- {
- table[sRow, sCol] = 'S';
- if (table[sRow + 1, sCol] == 'V' || table[sRow + 1, sCol] == 'X')
- {
- if (table[sRow + 1, sCol] == 'V')
- {
- niceKidsWithPresents++;
- }
- presents--;
- }
- if (table[sRow - 1, sCol] == 'V' || table[sRow - 1, sCol] == 'X')
- {
- if (table[sRow + 1, sCol] == 'V')
- {
- niceKidsWithPresents++;
- }
- presents--;
- }
- if (table[sRow, sCol + 1] == 'V' || table[sRow, sCol + 1] == 'X')
- {
- if (table[sRow + 1, sCol] == 'V')
- {
- niceKidsWithPresents++;
- }
- presents--;
- }
- if (table[sRow + 1, sCol - 1] == 'V' || table[sRow + 1, sCol - 1] == 'X')
- {
- if (table[sRow + 1, sCol] == 'V')
- {
- niceKidsWithPresents++;
- }
- presents--;
- }
- }
- if (table[sRow, sCol] == 'V')
- {
- niceKidsWithPresents++;
- presents--;
- table[sRow, sCol] = 'S';
- }
- if (table[sRow, sCol] == 'X')
- {
- table[sRow, sCol] = 'S';
- }
- break;
- case "left":
- table[sRow, sCol] = '-';
- sCol -= 1;
- if (sCol < 0)
- {
- sCol = cols - 1;
- }
- if (table[sRow, sCol] == 'C')
- {
- table[sRow, sCol] = 'S';
- if (table[sRow + 1, sCol] == 'V' || table[sRow + 1, sCol] == 'X')
- {
- if (table[sRow + 1, sCol] == 'V')
- {
- niceKidsWithPresents++;
- }
- presents--;
- }
- if (table[sRow - 1, sCol] == 'V' || table[sRow - 1, sCol] == 'X')
- {
- if (table[sRow + 1, sCol] == 'V')
- {
- niceKidsWithPresents++;
- }
- presents--;
- }
- if (table[sRow, sCol + 1] == 'V' || table[sRow, sCol + 1] == 'X')
- {
- if (table[sRow + 1, sCol] == 'V')
- {
- niceKidsWithPresents++;
- }
- presents--;
- }
- if (table[sRow + 1, sCol - 1] == 'V' || table[sRow + 1, sCol - 1] == 'X')
- {
- if (table[sRow + 1, sCol] == 'V')
- {
- niceKidsWithPresents++;
- }
- presents--;
- }
- }
- if (table[sRow, sCol] == 'V')
- {
- niceKidsWithPresents++;
- presents--;
- table[sRow, sCol] = 'S';
- }
- if (table[sRow, sCol] == 'X')
- {
- table[sRow, sCol] = 'S';
- }
- break;
- case "right":
- table[sRow, sCol] = '-';
- sCol += 1;
- if (sCol > cols-1)
- {
- sCol = cols - 1;
- }
- if (table[sRow, sCol] == 'C')
- {
- table[sRow, sCol] = 'S';
- if (table[sRow + 1, sCol] == 'V' || table[sRow + 1, sCol] == 'X')
- {
- if (table[sRow + 1, sCol] == 'V')
- {
- niceKidsWithPresents++;
- }
- presents--;
- }
- if (table[sRow - 1, sCol] == 'V' || table[sRow - 1, sCol] == 'X')
- {
- if (table[sRow + 1, sCol] == 'V')
- {
- niceKidsWithPresents++;
- }
- presents--;
- }
- if (table[sRow, sCol + 1] == 'V' || table[sRow, sCol + 1] == 'X')
- {
- if (table[sRow + 1, sCol] == 'V')
- {
- niceKidsWithPresents++;
- }
- presents--;
- }
- if (table[sRow + 1, sCol - 1] == 'V' || table[sRow + 1, sCol - 1] == 'X')
- {
- if (table[sRow + 1, sCol] == 'V')
- {
- niceKidsWithPresents++;
- }
- presents--;
- }
- }
- if (table[sRow, sCol] == 'V')
- {
- niceKidsWithPresents++;
- presents--;
- table[sRow, sCol] = 'S';
- }
- if (table[sRow, sCol] == 'X')
- {
- table[sRow, sCol] = 'S';
- }
- break;
- default:
- break;
- }
- command = Console.ReadLine();
- }
- }
- private static void PrintTable(int rows, int cols, char[,] table)
- {
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < cols; col++)
- {
- Console.Write(table[row, col]);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment