fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8. class Program
  9. {
  10. static IEnumerable<int> Range(int start, int end, int step = 1)
  11. {
  12. while (start <= end)
  13. {
  14. yield return start;
  15. start += step;
  16. }
  17. }
  18.  
  19. static void Main(string[] args)
  20. {
  21. string str = "2,5,7-10,11,17-18";
  22.  
  23. var output = from n in str.Split(',')
  24. let splitted = n.Split('-')
  25. let start = int.Parse(splitted[0])
  26. let end = int.Parse(splitted.Last())
  27. select Range(start, end, 1);
  28.  
  29. foreach (var it in output)
  30. foreach (var i in it)
  31. Console.WriteLine(i);
  32. }
  33. }
  34. }
  35.  
Success #stdin #stdout 0.04s 34032KB
stdin
Standard input is empty
stdout
2
5
7
8
9
10
11
17
18