fork(1) download
  1. #!/usr/bin/perl
  2. for (<STDIN>){
  3. @b = ();
  4. for (/([-\d]+)/g) {
  5. my @a = map{$_>99999?99999:$_} /(\d+)/g;
  6. $a[1] = $a[0] unless $a[1];
  7. ($a[1], $a[0]) = ($a[0], $a[1]) if $a[0] > $a[1];
  8. push @b, [@a];
  9. }
  10. @c = sort{$a->[0] <=> $b->[0]} @b;
  11. $i = $c[0][0]-1;
  12. my @d;
  13. for (@c) {
  14. for ($_->[0] .. $_->[1]) {
  15. if ($i < $_) {
  16. push @d, $_;
  17. $i = $_;
  18. }
  19. }
  20. }
  21. print '['.join(',', @d)."]\n";
  22. }
Success #stdin #stdout 0s 18256KB
stdin
>>1
>>1-3
>>1,3
>>1-3,5,9-10
>>000000-000000001
>>289494
>>0-2,99998-100000
>>3,0-3,4,5,6,4,2-8
>>4-1
stdout
>>1
[1]
>>1-3
[1,2,3]
>>1,3
[1,3]
>>1-3,5,9-10
[1,2,3,5,9,10]
>>000000-000000001
[0,1]
>>289494
[99999]
>>0-2,99998-100000
[0,1,2,99998,99999]
>>3,0-3,4,5,6,4,2-8
[0,1,2,3,4,5,6,7,8]
>>4-1
[1,2,3,4]