fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <regex>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. string s;
  10. cin >> s;
  11.  
  12. cout << regex_replace
  13. (
  14. regex_replace
  15. (
  16. regex_replace
  17. (
  18. s,
  19. regex("\\d+\\b"),
  20. "$&#$&-$&"
  21. ) + "0123456789",
  22. regex("(\\b(?=9.*(1))|0(?=.*(1))|1(?=.*(2))|2(?=.*(3))|3(?=.*(4))|4(?=.*(5))|5(?=.*(6))|6(?=.*(7))|7(?=.*(8))|8(?=.*(9))|9(?=.*(0)))(?=9*-)|\\d{10}$"),
  23. "$2$3$4$5$6$7$8$9$10$11$12"
  24. ),
  25. regex("(#(\\d+)-\\d+,\\2\\b)+#\\d+|#\\d+-\\d+"),
  26. ""
  27. ) << '\n';
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 3508KB
stdin
1,3,4,5,6,7,8,10,12,16,17,20,21,22,23,24,28,29,30,31,96,97,98,99,100,101,102
stdout
1,3-8,10,12,16-17,20-24,28-31,96-99,100-1021