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> target = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToList();
- string input;
- while ((input = Console.ReadLine()) != "End")
- {
- string[] manipulation = input.Split().ToArray();
- string option = manipulation[0];
- int index = int.Parse(manipulation[1]);
- int value = int.Parse(manipulation[2]);
- switch (option)
- {
- case "Add":
- if (index < target.Count && index >= 0)
- {
- target.Insert(index, value);
- }
- else
- {
- Console.WriteLine("Invalid placement!");
- }
- break;
- case "Shoot":
- if (index < target.Count && index >= 0)
- {
- if (target[index] > value)
- {
- target[index] -= value;
- }
- else
- {
- target.RemoveAt(index);
- }
- }
- break;
- case "Strike":
- int start = index - value;
- int end = index + value;
- if (start >= 0 && end < target.Count)
- {
- target.RemoveRange(start, end - start + 1);
- }
- else
- {
- Console.WriteLine("Strike missed!");
- }
- break;
- }
- }
- Console.WriteLine(string.Join("|", target));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement