Advertisement
Iskrenov84

Untitled

Feb 20th, 2022
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 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 travеlled {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. if (fuel > 0)
  52. {
  53. Console.WriteLine($"An enemy with {tokens[1]} armour is outmaneuvered.");
  54. }
  55. }
  56.  
  57. break;
  58. case "Repair":
  59. fuel += int.Parse(tokens[1]);
  60. ammunition += int.Parse(tokens[1]) * 2;
  61. Console.WriteLine($"Ammunitions added: {int.Parse(tokens[1]) * 2}.");
  62. Console.WriteLine($"Fuеl added: {int.Parse(tokens[1])}.");
  63. break;
  64. case "Titan":
  65. Console.WriteLine("You have reached Titan, all passengers are safe.");
  66. break;
  67. }
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement