Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace fundamental14
- {
- class MainClass
- {
- public static void Main()
- {
- List<int> pirateship = Console.ReadLine().Split(">").Select(int.Parse).ToList();
- List<int> warship = Console.ReadLine().Split(">").Select(int.Parse).ToList();
- int helty = int.Parse(Console.ReadLine());
- int result = 0;
- string input = string.Empty;
- while ((input = Console.ReadLine()) != "Retire")
- {
- string[] array = input.Split();
- string command = array[0];
- if (command == "Fire")
- {
- int index = int.Parse(array[1]);
- int damage = int.Parse(array[2]);
- if (index < warship.Count && index >= 0)
- {
- if (damage > 0)
- {
- warship[index] -= damage;
- if (warship[index] <= 0)
- {
- Console.WriteLine("You won! The enemy ship has sunken.");
- result++;
- break;
- }
- }
- }
- }
- else if (command == "Defend")
- {
- int startIndex = int.Parse(array[1]);
- int endIndex = int.Parse(array[2]);
- int damage = int.Parse(array[3]);
- if (damage > 0)
- {
- if (startIndex < pirateship.Count && startIndex >= 0 && endIndex < pirateship.Count && endIndex >= 0 && endIndex > startIndex)
- {
- for (int i = startIndex; i <= endIndex; i++)
- {
- pirateship[i] -= damage;
- if (pirateship[i] <= 0)
- {
- Console.WriteLine("You lost! The pirate ship has sunken.");
- result++;
- break;
- }
- }
- }
- }
- }
- else if (command == "Repair")
- {
- int index = int.Parse(array[1]);
- int repair = int.Parse(array[2]);
- if(index < pirateship.Count && index >= 0)
- {
- pirateship[index] += repair;
- if (pirateship[index] > helty)
- {
- pirateship[index] = helty;
- }
- }
- }
- else if (command == "Status")
- {
- int needToRepaera = (int)(helty * 0.2);
- int sum = 0;
- for (int i = 0; i < pirateship.Count; i++)
- {
- if (needToRepaera > pirateship[i])
- {
- sum++;
- }
- }
- Console.WriteLine($"{sum} sections need repair.");
- }
- }
- if (result == 0)
- {
- Console.WriteLine("Pirate ship status: {0}", pirateship.Sum());
- Console.WriteLine("Warship status: {0}", warship.Sum());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement