Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class CollectCoins
- {
- static void Main()
- {
- string[] board = new string[4];
- for (int i = 0; i < 4; i++)
- {
- board[i] = Console.ReadLine();
- }
- string command = Console.ReadLine();
- int coins = 0;
- int wallsHit = 0;
- int x = 0, y = 0;//player position
- for (int i = 0; i < command.Length; i++)
- {
- try
- {
- switch (command[i])
- {
- case 'V': x++; break;
- case '>': y++; break;
- case '^': x--; break;
- case '<': y--; break;
- }
- if (board[x][y] == '$')
- {
- coins++;
- }
- }
- catch (Exception)
- {
- wallsHit++;
- switch (command[i])
- {
- case 'V': x--; break;
- case '>': y--; break;
- case '^': x++; break;
- case '<': y++; break;
- }
- }
- }
- Console.WriteLine("Coins collected: {0}", coins);
- Console.WriteLine("Walls hit: {0}", wallsHit);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement