Advertisement
gospod1978

List-Ex/More/Take/Skip Rope

Oct 23rd, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. namespace fundamental14
  7. {
  8.     class MainClass
  9.     {
  10.         public static void Main()
  11.         {
  12.             string text = Console.ReadLine();
  13.             List<int> number = new List<int>();
  14.             List<string> textA = new List<string>();
  15.             StringBuilder result = new StringBuilder();
  16.  
  17.  
  18.  
  19.             for (int i = 0; i < text.Length; i++)
  20.             {
  21.                 if (char.IsDigit(text[i]))
  22.                 {
  23.                     number.Add(int.Parse((text[i]).ToString()));
  24.                 }
  25.                 else
  26.                 {
  27.                     textA.Add((text[i]).ToString());
  28.                 }
  29.             }
  30.  
  31.             List<int> take = new List<int>();
  32.  
  33.             List<int> skip = new List<int>();
  34.  
  35.             for (int i = 0; i < number.Count; i++)
  36.             {
  37.                 if (i % 2 != 0)
  38.                 {
  39.                     skip.Add(number[i]);
  40.                 }
  41.                 else
  42.                 {
  43.                     take.Add(number[i]);
  44.                 }
  45.             }
  46.             int indexOfSkip = 0;
  47.  
  48.             for (int i = 0; i < take.Count; i++)
  49.             {
  50.                 List<string> temp = new List<string>(textA);
  51.  
  52.                 temp = temp.Skip(indexOfSkip).Take(take[i]).ToList();
  53.  
  54.                 result.Append(string.Join("", temp));
  55.  
  56.                 indexOfSkip += take[i] + skip[i];
  57.                
  58.             }
  59.             Console.WriteLine(result.ToString());
  60.  
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement