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