skipter

C# Ballistics Training

Jun 23rd, 2017
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace _18.BallisticsTraining
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int[] cordinates = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  13.             string[] commands = Console.ReadLine().Split(' ');
  14.  
  15.             int x = 0;
  16.             int y = 0;
  17.  
  18.             for (int cnt = 0; cnt < commands.Length; cnt++)
  19.             {
  20.                 if (commands[cnt] == "up")
  21.                 {
  22.                     y += Convert.ToInt32(commands[cnt + 1]);
  23.                 }
  24.                 if (commands[cnt] == "down")
  25.                 {
  26.                     y -= Convert.ToInt32(commands[cnt + 1]);
  27.                 }
  28.                 if (commands[cnt] == "left")
  29.                 {
  30.                     x -= Convert.ToInt32(commands[cnt + 1]);                    
  31.                 }
  32.                 if (commands[cnt] == "right")
  33.                 {
  34.                     x += Convert.ToInt32(commands[cnt + 1]);                  
  35.                 }
  36.             }            
  37.                 if (cordinates[0] == x && cordinates[1] == y)
  38.             {
  39.                 Console.WriteLine("firing at [{0}, {1}]", cordinates[0], cordinates[1]);
  40.                 Console.WriteLine("got 'em!");
  41.             } else
  42.             {
  43.                 Console.WriteLine("firing at [{0}, {1}]", x, y);
  44.                 Console.WriteLine("better luck next time...");
  45.             }          
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment