Advertisement
YavorGrancharov

Ballistics_Training

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