Advertisement
silvana1303

moving target

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