SHARE
TWEET

Ballistics Training

kotunec Feb 11th, 2017 159 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _10.BallisticsTraining
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double[] target = Console.ReadLine().Split().Select(double.Parse).ToArray();
  14.             string[] input = Console.ReadLine().Split();
  15.  
  16.             double xCoordinate = 0;
  17.             double yCoordinate = 0;
  18.  
  19.             for (int i = 0; i < input.Length; i += 2)
  20.             {
  21.                 string command = input[i];
  22.                 double manipulatorIndex = double.Parse(input[i + 1]);
  23.  
  24.                 if (command.Equals("up"))
  25.                 {
  26.                     yCoordinate += manipulatorIndex;
  27.                 }
  28.                 else if (command.Equals("down"))
  29.                 {
  30.                     yCoordinate -= manipulatorIndex;
  31.                 }
  32.                 else if (command.Equals("left"))
  33.                 {
  34.                     xCoordinate -= manipulatorIndex;
  35.                 }
  36.                 else
  37.                 {
  38.                     xCoordinate += manipulatorIndex;
  39.                 }
  40.  
  41.             }
  42.  
  43.             Console.WriteLine($"firing at [{xCoordinate}, {yCoordinate}]");
  44.  
  45.             if (xCoordinate.Equals(target[0]) && yCoordinate.Equals(target[1]))
  46.             {
  47.                 Console.WriteLine("got 'em!");
  48.             }
  49.  
  50.             else
  51.             {
  52.                 Console.WriteLine("better luck next time...");
  53.             }
  54.         }
  55.     }
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top