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.  
  24. print("\n",$temp);
  25.  
  26. while($temp>=$lowerlimit)
  27. {
  28. $word=substr($sortedarray[$temp],$mat,length($sortedarray[$temp]));
  29. if($word eq "")
  30. {
  31. push @oparray,"\\s";
  32. }
  33. else
  34. {
  35. push @oparray ,$word;
  36. }
  37.  
  38. $temp--;
  39. }
  40. print ("\n",@oparray);
  41. print("\n",$upperlimit);
  42. if(($upperlimit)==(scalar(@sortedarray)-1))
  43. {
  44. #print $upperlimit+1;
  45. #print "All the words are parsed";
  46. #last;
  47. }
  48. else
  49. {
  50. $lowerlimit=$upperlimit+1;
  51. $count=$lowerlimit;
  52. $inc=1;
  53. func();
  54. }
  55. }
  56. }
  57. print "All the words are parsed";
  58. sub func
  59. {
  60. if (defined $sortedarray[$count])
  61. {
  62. $base=substr($sortedarray[$count],0,$inc);
  63. }
  64. else
  65. {
  66. last;
  67. }
  68. if (defined $sortedarray[$count+1])
  69. {
  70. $match=substr($sortedarray[$count+1],0,$inc) ;
  71. }
  72. else
  73. {
  74. if (defined $sortedarray[$count-1])
  75. {
  76. $s=substr($sortedarray[$count-1],0,$inc);
  77. }
  78. else
  79. {
  80. last;
  81. }
  82. if($s eq $base)
  83. {
  84. $upperlimit=$count;
  85. $count = $lowerlimit;
  86. $inc++;
  87. #print $inc;
  88. func();
  89. }
  90. else
  91. {
  92. last;
  93. }
  94. }
  95. print("\n",$base," ",$match);
  96. $count++;
  97. if($base ne $match)
  98. {
  99. if(($count-1) == $lowerlimit)
  100. {
  101. my $lcount=$count;
  102. my $ucount=$count+1;
  103. if($ucount>=scalar(@sortedarray))
  104. {
  105. $upperlimit=$count;
  106. $mat=$inc-1;
  107. splitter();
  108. }
  109. else
  110. {
  111. my $ulimit=$upperlimit;
  112. print("\n",$lcount,"\n",$ucount,"\n",$ulimit);
  113. while($ulimit>=$count)
  114. {
  115. my $new=substr($sortedarray[$lcount],0,$inc);
  116. print("\n",$new);
  117. my $new1=substr($sortedarray[$ucount],0,$inc);
  118. print(" ",$new1);
  119. if($new eq $new1)
  120. {
  121. $upperlimit=$lcount-1;
  122. print("\n",$upperlimit);
  123. $mat=$inc-1;
  124. print("\n",$mat);
  125. splitter();
  126. }
  127. else
  128. {
  129. $ulimit--;
  130. $lcount++;
  131. $ucount++;
  132. print("\n",$lcount,"\n",$ucount,"\n",$ulimit);
  133. }
  134. }
  135. $mat=$inc-1;
  136. print $mat;
  137. splitter();
  138. }
  139. }
  140. else
  141. {
  142. $inc++;
  143. print $inc;
  144. unless(($count) == $upperlimit)
  145. {
  146. $count=$lowerlimit;
  147. func();
  148. }
  149. }
  150. }
  151. else
  152. {
  153. $upperlimit=$count;
  154. func();
  155. }
  156. }
  157. func();
  158.  
Success #stdin #stdout 0s 4724KB
stdin
Standard input is empty
stdout
All the words are parsed
r r
r r
r r
r r
r r
r r
r r
re re
re re
re re
re re
re re
re re
re re
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
5
2
5
turnsponselmignbelal
5
r r
re re
rev rev
reve reve
revea rever
7
turnsponselmignbelalrtal
7
revea rever6
reveal revert
7
turnsponselmignbelalrtaltl
7
reveal revert7
reveal revert
7
turnsponselmignbelalrtaltl\s\s
7
reveal revert8
reveal revert
7
turnsponselmignbelalrtaltl\s\s\s\s
7
reveal revert9
reveal revert
7
turnsponselmignbelalrtaltl\s\s\s\s\s\s
78
7
turnsponselmignbelalrtaltl\s\s\s\s\s\s\s\s
7
reveal revert10
reveal revert
7
turnsponselmignbelalrtaltl\s\s\s\s\s\s\s\s\s\s
7
reveal revert11
reveal revert
7
turnsponselmignbelalrtaltl\s\s\s\s\s\s\s\s\s\s\s\s
7