Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Moving_Target
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> targets = Console.ReadLine().Split().Select(int.Parse).ToList();
- string input;
- while ((input = Console.ReadLine()) != "End")
- {
- string[] arguments = input.Split();
- string command = arguments[0];
- int index = int.Parse(arguments[1]);
- if (command == "Shoot")
- {
- int power = int.Parse(arguments[2]);
- if (index >= 0 && index < targets.Count)
- {
- targets[index] -= power;
- if (targets[index] <= 0)
- {
- targets.Remove(targets[index]);
- }
- }
- }
- else if (command == "Add")
- {
- int value = int.Parse(arguments[2]);
- if (index >= 0 && index < targets.Count)
- {
- targets.Insert(index, value);
- }
- else
- {
- Console.WriteLine("Invalid placement!");
- }
- }
- else if (command == "Strike")
- {
- int range = int.Parse(arguments[2]);
- int startIndex = index - range;
- int digits = (index + range) - startIndex;
- if ((index + range) < targets.Count && startIndex >= 0)
- {
- targets.RemoveRange(startIndex, digits + 1);
- }
- else
- {
- Console.WriteLine("Strike missed!");
- }
- }
- }
- Console.WriteLine(string.Join("|", targets));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement