Advertisement
grubcho

Ballistics training

Jun 20th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 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.  
  7. namespace Ballistics_training
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] coordinates = Console.ReadLine().Split(' ');
  14.             string[] input = Console.ReadLine().Split(' ');
  15.             string[] commands = new string[input.Length/2];
  16.             int tempCount = 0;
  17.             for (int i = 0; i < commands.Length; i++)
  18.             {
  19.                 commands[i] = input[tempCount];
  20.                 tempCount += 2;
  21.             }
  22.             tempCount = 1;
  23.             string[] moves = new string[commands.Length];
  24.             for (int i = 0; i < moves.Length; i++)
  25.             {
  26.                 moves[i] = input[tempCount];
  27.                 tempCount += 2;
  28.             }
  29.             double x = 0;
  30.             double y = 0;
  31.             for (int i = 0; i < commands.Length; i++)
  32.             {
  33.                 if (commands[i] == "left")
  34.                 {
  35.                     x -= double.Parse(moves[i]);
  36.                 }
  37.                 else if (commands[i] == "right")
  38.                 {
  39.                     x += double.Parse(moves[i]);
  40.                 }
  41.                 else if (commands[i] == "up")
  42.                 {
  43.                     y += double.Parse(moves[i]);
  44.                 }
  45.                 else if (commands[i] == "down")
  46.                 {
  47.                     y -= double.Parse(moves[i]);
  48.                 }
  49.             }
  50.             if (x == double.Parse(coordinates[0]) && y == double.Parse(coordinates[1]))
  51.             {
  52.                 Console.WriteLine($"firing at [{x}, {y}]");
  53.                 Console.WriteLine("got 'em!");
  54.             }
  55.             else
  56.             {
  57.                 Console.WriteLine($"firing at [{x}, {y}]");
  58.                 Console.WriteLine("better luck next time...");
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement