Advertisement
DeeAG

03.Take_SkipRope

Apr 23rd, 2021
788
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _03.Take_SkipRope
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string input = Console.ReadLine();
  13.  
  14.             List<string> text = new List<string>();
  15.             List<int> numbers = new List<int>();
  16.             List<int> takeList = new List<int>();
  17.             List<int> skipList = new List<int>();
  18.             string result = string.Empty;
  19.             //numbers = input
  20.             //    .Where(x => char.IsDigit(x))
  21.             //    .Select(x => x.ToString())
  22.             //    .Select(int.Parse)
  23.             //    .ToList();
  24.  
  25.             for (int i = 0; i < input.Length; i++)
  26.             {
  27.                 if (char.IsDigit(input[i]))
  28.                 {
  29.                     numbers.Add(int.Parse(input[i].ToString()));
  30.                 }
  31.                 else
  32.                 {
  33.                     text.Add(input[i].ToString());
  34.                 }
  35.             }
  36.             for (int i = 0; i < numbers.Count; i++)
  37.             {
  38.                 if (i % 2 == 0)
  39.                 {
  40.                     takeList.Add(numbers[i]);
  41.                 }
  42.                 else
  43.                 {
  44.                     skipList.Add(numbers[i]);
  45.                 }
  46.             }
  47.             int index = 0;
  48.             for (int i = 0; i < takeList.Count; i++)
  49.             {
  50.                 int take = takeList[i];
  51.                 int skipe = skipList[i];
  52.  
  53.                 if (index + take > text.Count)
  54.                 {
  55.                     take = text.Count - index;
  56.                 }
  57.  
  58.                 for (int j = 0; j < take; j++)
  59.                 {
  60.                     result += text[index + j];
  61.                 }
  62.  
  63.                 index += take + skipe;
  64.             }
  65.  
  66.             Console.WriteLine(result);
  67.         }
  68.     }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement