fork download
  1. namespace _07.Take_Or_Skip_Rope
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.Linq;
  7. using System.Text.RegularExpressions;
  8. using System.Text;
  9.  
  10. public class TakeOrSkipRope
  11. {
  12. public static void Main()
  13. {
  14. var text = Console.ReadLine();
  15.  
  16. var numbersList = new List<int>();
  17. numbersList = GetNumbersList(text);
  18. var textWithoutDigits = GetTextWithoutDigits(text);
  19.  
  20. var takeList = GetTakeList(numbersList);
  21. var skipList = GetSkipList(numbersList);
  22.  
  23. var result = new StringBuilder();
  24. var skipTotal = 0;
  25.  
  26. for (int i = 0; i < skipList.Count; i++)
  27. {
  28. result.Append(string.Concat(textWithoutDigits.Skip(skipTotal).Take(takeList[i])));
  29. skipTotal += takeList[i] + skipList[i];
  30. }
  31.  
  32. Console.WriteLine(result.ToString());
  33. }
  34.  
  35. public static List<int> GetNumbersList(string text)
  36. {
  37. var numbersList = new List<int>();
  38.  
  39. foreach (var letter in text)
  40. {
  41. if (char.IsNumber(letter))
  42. {
  43. numbersList.Add(int.Parse(letter.ToString()));
  44. }
  45. }
  46.  
  47. return numbersList;
  48. }
  49.  
  50. public static string GetTextWithoutDigits(string text)
  51. {
  52. var sb = new StringBuilder();
  53.  
  54. foreach (var letter in text)
  55. {
  56. if (!char.IsNumber(letter))
  57. {
  58. sb.Append(letter);
  59. }
  60. }
  61.  
  62. return sb.ToString();
  63. }
  64.  
  65. public static List<int> GetSkipList (List<int> numbers)
  66. {
  67. var skipList = new List<int>();
  68.  
  69. for (int i = 1; i < numbers.Count; i+=2)
  70. {
  71. skipList.Add(numbers[i]);
  72. }
  73.  
  74. return skipList;
  75. }
  76.  
  77. public static List<int> GetTakeList(List<int> numbers)
  78. {
  79. var takeList = new List<int>();
  80.  
  81. for (int i = 0; i < numbers.Count; i += 2)
  82. {
  83. takeList.Add(numbers[i]);
  84. }
  85.  
  86. return takeList;
  87. }
  88. }
  89. }
Runtime error #stdin #stdout #stderr 0.01s 135936KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
  at _07.Take_Or_Skip_Rope.TakeOrSkipRope.GetNumbersList (System.String text) [0x0003e] in <4d9ee629e3a1400384ab15e4547462dd>:0 
  at _07.Take_Or_Skip_Rope.TakeOrSkipRope.Main () [0x0000c] in <4d9ee629e3a1400384ab15e4547462dd>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
  at _07.Take_Or_Skip_Rope.TakeOrSkipRope.GetNumbersList (System.String text) [0x0003e] in <4d9ee629e3a1400384ab15e4547462dd>:0 
  at _07.Take_Or_Skip_Rope.TakeOrSkipRope.Main () [0x0000c] in <4d9ee629e3a1400384ab15e4547462dd>:0