fork(1) download
  1. open $in, '<', "shortest-accepted.in";
  2. <>;
  3. while(<>){
  4. s/\$+/()/g;
  5.  
  6. 1 while 0
  7. || s/ \w \*+ //x
  8. || s/ (?> (?<![)*]) (\w*) \| (\w*) ) (?![(]) /
  9. $capture_1 = $1, $capture_2 = $2,
  10. (
  11. sort { (length $a) <=> (length $b) || $a cmp $b } ( $capture_1, $capture_2 )
  12. )[0]
  13. /xe
  14. || s/\( (\w*) \) \*+ //x
  15. || s/\( (\w*) \) /$1/x ;
  16.  
  17. (length) or $_ = q($);
  18. print $_, "\n"
  19. }
Success #stdin #stdout 0s 6000KB
stdin
3
()()****
((())***bb|aa)
((a***))*
(a)(a**b***)
a*|b*
(aaa)(bb)|(c(dd))
(aaaaa|bbbbb)ee|cccccc
(a|$)
(aa|bbb|ccc)
(|)
($$$$$$)aa|bbb(a$bb$ccc$*$*$a*aaa*bb*)
(|()()()*||)
((bbb$|$*)|$bb)
()a|bb|ccc|(a|b)
(a(b(c(d|e))))
a
ab|ac*(ca|cb)
((ab|ac)a)*
abababcccc
ab*a*a*a*ccc*b*
(a|cb)a(bbb|cb)
(aaaaaaa|bbbb(aaa|cccc)bbbbb)
(aaaaaaa|bbbb(aaa|cccc)*bbbbb)
(aaaaaaa|bbbb(aaa|cccc)bbbbb)*
(aaaaaaaaaaaaaaaaaaaaa|bbbb(aaa|cccc)*bbbbb)
((b)*|a)
((b)(c|c*)|a*(aaa|bbb*))
($)($)()abc(bbc)*abc
stdout
$
bb
$
a
$
cdd
aaaaaee
$
aa
$
aa
$
$
a
abcd
a
ab
$
abababcccc
acc
aacb
aaaaaaa
aaaaaaa
$
bbbbbbbbb
$
b
abcabc