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