Advertisement
Guest User

Untitled

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