Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Moving_Target
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> targets = Console.ReadLine().Split().Select(int.Parse).ToList();
  12.  
  13.             string input;
  14.             while ((input = Console.ReadLine()) != "End")
  15.             {
  16.                 string[] arguments = input.Split();
  17.                 string command = arguments[0];
  18.                 int index = int.Parse(arguments[1]);
  19.  
  20.                 if (command == "Shoot")
  21.                 {                  
  22.                     int power = int.Parse(arguments[2]);
  23.                     if (index >= 0 && index < targets.Count)
  24.                     {
  25.                         targets[index] -= power;
  26.                         if (targets[index] <= 0)
  27.                         {
  28.                             targets.Remove(targets[index]);
  29.                         }
  30.                     }
  31.                 }
  32.                 else if (command == "Add")
  33.                 {
  34.                     int value = int.Parse(arguments[2]);
  35.                     if (index >= 0 && index < targets.Count)
  36.                     {
  37.                         targets.Insert(index, value);
  38.                     }
  39.                     else
  40.                     {
  41.                         Console.WriteLine("Invalid placement!");
  42.                     }
  43.                 }
  44.                 else if (command == "Strike")
  45.                 {
  46.                     int range = int.Parse(arguments[2]);
  47.                     int startIndex = index - range;
  48.                     int digits = (index + range) - startIndex;
  49.                     if ((index + range) < targets.Count && startIndex >= 0)
  50.                     {
  51.                         targets.RemoveRange(startIndex, digits + 1);
  52.                     }
  53.                     else
  54.                     {
  55.                         Console.WriteLine("Strike missed!");
  56.                     }
  57.                 }
  58.             }
  59.  
  60.                 Console.WriteLine(string.Join("|", targets));
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement