Advertisement
Guest User

Untitled

a guest
May 12th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. class CollectCoins
  5. {
  6.     static void Main()
  7.     {
  8.         string[] board = new string[4];
  9.         for (int i = 0; i < 4; i++)
  10.         {
  11.             board[i] = Console.ReadLine();
  12.         }
  13.         string command = Console.ReadLine();
  14.         int coins = 0;
  15.         int wallsHit = 0;
  16.         int x = 0, y = 0;//player position
  17.         for (int i = 0; i < command.Length; i++)
  18.         {
  19.             try
  20.             {
  21.                 switch (command[i])
  22.                 {
  23.                     case 'V': x++; break;
  24.                     case '>': y++; break;
  25.                     case '^': x--; break;
  26.                     case '<': y--; break;
  27.                 }
  28.                 if (board[x][y] == '$')
  29.                 {
  30.                     coins++;
  31.                 }
  32.  
  33.             }
  34.             catch (Exception)
  35.             {
  36.                 wallsHit++;
  37.                 switch (command[i])
  38.                 {
  39.                     case 'V': x--; break;
  40.                     case '>': y--; break;
  41.                     case '^': x++; break;
  42.                     case '<': y++; break;
  43.                 }
  44.             }
  45.         }
  46.         Console.WriteLine("Coins collected: {0}", coins);
  47.         Console.WriteLine("Walls hit: {0}", wallsHit);
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement