Advertisement
Guest User

Untitled

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