TheBulgarianWolf

Take/Skip Rope

Dec 28th, 2020 (edited)
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Take_SkipRope
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Console.WriteLine("Enter your string here: ");
  11.             string initialMessage = Console.ReadLine();
  12.             List<int> integers = new List<int>();
  13.             List<char> chars = new List<char>();
  14.            
  15.             for(int i = 0; i < initialMessage.Length; i++)
  16.             {
  17.                 if(initialMessage[i] >= 48 && initialMessage[i] <= 57)
  18.                 {
  19.                     integers.Add((initialMessage[i] - '0'));
  20.                 }
  21.                 else
  22.                 {
  23.                     chars.Add(initialMessage[i]);
  24.                 }
  25.             }
  26.  
  27.             List<int> takeList = new List<int>();
  28.             List<int> skipList = new List<int>();
  29.             for(int k = 0; k < integers.Count; k++)
  30.             {
  31.                 if(k%2 == 0)
  32.                 {
  33.                     takeList.Add(integers[k]);
  34.                 }
  35.                 else
  36.                 {
  37.                     skipList.Add(integers[k]);
  38.                 }
  39.             }
  40.             string result = "";
  41.             int iterations = takeList.Count;
  42.             int currentStart = 0;
  43.             for (int f = 0; f < iterations; f++)
  44.             {
  45.  
  46.  
  47.                 int increase = takeList[f];
  48.                 if(increase > chars.Count)
  49.                 {
  50.                     increase = chars.Count;
  51.                 }
  52.                 for (int h = currentStart; h < currentStart + increase; h++)
  53.                 {
  54.                     result += chars[h];
  55.                 }
  56.                 currentStart += takeList[f];
  57.                 currentStart += skipList[f];
  58.  
  59.             }
  60.  
  61.             Console.WriteLine(result);
  62.         }
  63.     }
  64. }
Add Comment
Please, Sign In to add comment