Advertisement
_CodeBehind

10.Ballistics_Training

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