Advertisement
bullit3189

Take Skip Rope - Lists

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