Advertisement
Guest User

Untitled

a guest
May 16th, 2020
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 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> target = Console.ReadLine()
  12.                 .Split()
  13.                 .Select(int.Parse)
  14.                 .ToList();
  15.  
  16.             string input;
  17.             while ((input = Console.ReadLine()) != "End")
  18.             {
  19.                 string[] manipulation = input.Split().ToArray();
  20.                 string option = manipulation[0];
  21.                 int index = int.Parse(manipulation[1]);
  22.                 int value = int.Parse(manipulation[2]);
  23.  
  24.                 switch (option)
  25.                 {
  26.                     case "Add":
  27.                         if (index < target.Count && index >= 0)
  28.                         {
  29.                             target.Insert(index, value);
  30.                         }
  31.                         else
  32.                         {
  33.                             Console.WriteLine("Invalid placement!");
  34.                         }
  35.  
  36.                         break;
  37.                     case "Shoot":
  38.                         if (index < target.Count && index >= 0)
  39.                         {
  40.                             if (target[index] > value)
  41.                             {
  42.                                 target[index] -= value;
  43.                             }
  44.                             else
  45.                             {
  46.                                 target.RemoveAt(index);
  47.                             }
  48.                         }
  49.  
  50.                         break;
  51.                     case "Strike":
  52.                         int start = index - value;
  53.                         int end = index + value;
  54.                         if (start >= 0 && end < target.Count)
  55.                         {
  56.                             target.RemoveRange(start, end - start + 1);
  57.                         }
  58.                         else
  59.                         {
  60.                             Console.WriteLine("Strike missed!");
  61.                         }
  62.  
  63.                         break;
  64.                 }
  65.             }
  66.  
  67.             Console.WriteLine(string.Join("|", target));
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement