Advertisement
Iskrenov84

Space travel

Feb 20th, 2022
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5.  
  6. class Program
  7. {
  8.     static void Main()
  9.     {
  10.         List<string> route = Console.ReadLine()
  11.             .Split("||", StringSplitOptions.RemoveEmptyEntries)
  12.             .ToList();
  13.         int fuel = int.Parse(Console.ReadLine());
  14.         int ammunition = int.Parse(Console.ReadLine());
  15.        
  16.         for (int i = 0; i < route.Count; i++)
  17.         {
  18.             string[] tokens = route[i].Split(' ');
  19.  
  20.             switch (tokens[0])
  21.             {
  22.                 case "Travel":
  23.                     if (int.Parse(tokens[1]) <= fuel)
  24.                     {
  25.                         fuel -=int.Parse(tokens[1]);
  26.                         Console.WriteLine($"The spaceship travalled {tokens[1]} light-years.");
  27.                     }
  28.                     else
  29.                     {
  30.                         Console.WriteLine("Mission failed.");
  31.                         return;
  32.                     }
  33.                     break;
  34.                 case "Enemy":
  35.                     if (ammunition >= int.Parse(tokens[1]))
  36.                     {
  37.                         ammunition -= int.Parse(tokens[1]);
  38.                         Console.WriteLine($"An enemy with {tokens[1]} armour is defeated");
  39.                     }
  40.                     else
  41.                     {
  42.                         for (int k = 0; k < int.Parse(tokens[1]); k++)
  43.                         {
  44.                             fuel -= 2;
  45.                         }
  46.                         if (fuel <= 0 || ammunition < 0)
  47.                         {
  48.                             Console.WriteLine("Mission failed.");
  49.                             return;
  50.                         }
  51.                     }
  52.                     if (fuel > 0)
  53.                     {
  54.                         Console.WriteLine($"An enemy with {tokens[1]} armour is outmaneuvered.");
  55.                     }
  56.                     break;
  57.                 case "Repair":
  58.                     fuel += int.Parse(tokens[1]);
  59.                     ammunition += int.Parse(tokens[1]) * 2;
  60.                     Console.WriteLine($"Ammunitions added: {int.Parse(tokens[1]) * 2}.");
  61.                     Console.WriteLine($"Furl added: {int.Parse(tokens[1])}.");
  62.                     break;
  63.                 case "Titan":
  64.                     Console.WriteLine("You have reached Titan, all passengers are safe.");
  65.                     break;
  66.             }
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement