Advertisement
Spocoman

03. Take/Skip Rope

Feb 5th, 2022
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace TakeSkipRope
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string message = Console.ReadLine();
  12.  
  13.             List<char> numberList = message.Where(x => x >= '0' && x <= '9').ToList();
  14.             List<char> nonNumberList = message.Where(x => x < '0' || x > '9').ToList();
  15.             int modificationIndex = 0;
  16.  
  17.             for (int i = 0; i < numberList.Count; i += 2)
  18.             {
  19.                 modificationIndex += numberList[i] - 48;
  20.                 int finalIndex = modificationIndex + numberList[i + 1] - 48;
  21.                 finalIndex = finalIndex >= nonNumberList.Count ? nonNumberList.Count : finalIndex;
  22.  
  23.                 for (int j = modificationIndex; j < finalIndex; j++)
  24.                 {
  25.                     nonNumberList.RemoveAt(modificationIndex);
  26.                 }
  27.             }
  28.             while (modificationIndex < nonNumberList.Count)
  29.             {
  30.                 nonNumberList.RemoveAt(modificationIndex);
  31.             }
  32.             Console.WriteLine(string.Join("", nonNumberList));
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement