fork download
  1. use warnings;
  2. my @iparray=("return","revert","reveal","rebel","real","relm","reign","response");
  3. my @sortedarray=sort(@iparray);
  4. my @oparray;
  5. my $lowerlimit=0;
  6. my $upperlimit;
  7. my $count=0;
  8. my $inc=1;
  9. my $mat=0;
  10. my $matchedstring;
  11. sub splitter
  12. {
  13. if($mat==0)
  14. {
  15. $lowerlimit=$lowerlimit+1;
  16. $count=$lowerlimit;
  17. func();
  18. }
  19. else
  20. {
  21. $matchedstring=substr($sortedarray[$count-1],0,$mat);
  22. my $temp=$upperlimit;
  23. while($temp>=$lowerlimit)
  24. {
  25. $word=substr($sortedarray[$temp],$mat,length($sortedarray[$temp]));
  26. if($word eq "")
  27. {
  28. push @oparray,"\\s";
  29. }
  30. else
  31. {
  32. push @oparray ,$word;
  33. }
  34.  
  35. $temp--;
  36. }
  37. print ("\n",@oparray);
  38. if($upperlimit==scalar(@sortedarray))
  39. {
  40. print "All the words are parsed";
  41. last;
  42. }
  43. else
  44. {
  45. $lowerlimit=$upperlimit+1;
  46. $count=$lowerlimit;
  47. $inc=1;
  48. func();
  49. }
  50. }
  51. }
  52. sub func
  53. {
  54. $base=substr($sortedarray[$count],0,$inc);
  55. if (defined $sortedarray[$count+1])
  56. {
  57. $match=substr($sortedarray[$count+1],0,$inc) ;
  58. }
  59. else
  60. {
  61. $s=substr($sortedarray[$count-1],0,$inc);
  62. if($s eq $base)
  63. {
  64. $count = $lowerlimit;
  65. $inc++;
  66. print $inc;
  67. func();
  68. }
  69. else
  70. {
  71. last;
  72. }
  73. }
  74. print("\n",$base," ",$match);
  75. $count++;
  76. if($base ne $match)
  77. {
  78. if(($count-1) == $lowerlimit)
  79. {
  80. my $lcount=$count;
  81. my $ucount=$count+1;
  82. my $ulimit=$upperlimit;
  83. print("\n",$lcount,"\n",$ucount,"\n",$ulimit);
  84. while($ulimit>=0)
  85. {
  86. my $new=substr($sortedarray[$lcount],0,$inc);
  87. print("\n",$new);
  88. my $new1=substr($sortedarray[$ucount],0,$inc);
  89. print(" ",$new1);
  90. if($new eq $new1)
  91. {
  92. $upperlimit=$lcount;
  93. print("\n",$upperlimit);
  94. splitter();
  95. }
  96. else
  97. {
  98. $ulimit--;
  99. $lcount++;
  100. $ucount++;
  101. print("\n",$lcount,"\n",$ucount,"\n",$ulimit);
  102. }
  103. }
  104. $mat=$inc-1;
  105. print $mat;
  106. splitter();
  107. }
  108. else
  109. {
  110. $inc++;
  111. print $inc;
  112. unless(($count) == $upperlimit)
  113. {
  114. $count=$lowerlimit;
  115. func();
  116. }
  117. }
  118. }
  119. else
  120. {
  121. $upperlimit=$count;
  122. func();
  123. }
  124. }
  125. func();
  126.  
Runtime error #stdin #stdout 0s 4728KB
stdin
Standard input is empty
stdout
r r
r r
r r
r r
r r
r r
r r2
re re
re re
re re
re re
re re
re re
re re3
rea reb
1
2
7
reb rei
2
3
6
rei rel
3
4
5
rel res
4
5
4
res ret
5
6
3
ret rev
6
7
2
rev rev
6
reb rei
2
3
6
rei rel
3
4
5
rel res
4
5
4
res ret
5
6
3
ret rev
6
7
2
rev rev
6
rei rel
3
4
6
rel res
4
5
5
res ret
5
6
4
ret rev
6
7
3
rev rev
6
rel res
4
5
6
res ret
5
6
5
ret rev
6
7
4
rev rev
6
res ret
5
6
6
ret rev
6
7
5
rev rev
6
ret rev
6
7
6
rev rev
6
rev rev4
reve reve5
revea rever
7
8
7
rever 
8
9
6
 
84
\srtAll the words are parsed4
\srt\srtAll the words are parsed4
\srt\srt\srtAll the words are parsed4
\srt\srt\srt\srtAll the words are parsed4
\srt\srt\srt\srt\srtAll the words are parsed4
\srt\srt\srt\srt\srt\srtAll the words are parsed4
\srt\srt\srt\srt\srt\srt\srtAll the words are parsed