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+1)>=scalar(@sortedarray))
  43. {
  44. print "All the words are parsed";
  45. last;
  46. }
  47. else
  48. {
  49. $lowerlimit=$upperlimit+1;
  50. $count=$lowerlimit;
  51. $inc=1;
  52. func();
  53. }
  54. }
  55. }
  56. sub func
  57. {
  58. if (defined $sortedarray[$count])
  59. {
  60. $base=substr($sortedarray[$count],0,$inc);
  61. }
  62. if (defined $sortedarray[$count+1])
  63. {
  64. $match=substr($sortedarray[$count+1],0,$inc) ;
  65. }
  66. else
  67. {
  68. if (defined $sortedarray[$count-1])
  69. {
  70. $s=substr($sortedarray[$count-1],0,$inc);
  71. }
  72. if($s eq $base)
  73. {
  74. $upperlimit=$count;
  75. $count = $lowerlimit;
  76. $inc++;
  77. #print $inc;
  78. func();
  79. }
  80. else
  81. {
  82. last;
  83. }
  84. }
  85. print("\n",$base," ",$match);
  86. $count++;
  87. if($base ne $match)
  88. {
  89. if(($count-1) == $lowerlimit)
  90. {
  91. my $lcount=$count;
  92. my $ucount=$count+1;
  93. if($ucount>=scalar(@sortedarray))
  94. {
  95. $upperlimit=$count;
  96. $mat=$inc-1;
  97. splitter();
  98. }
  99. else
  100. {
  101. my $ulimit=$upperlimit;
  102. print("\n",$lcount,"\n",$ucount,"\n",$ulimit);
  103. while($ulimit>=$count)
  104. {
  105. my $new=substr($sortedarray[$lcount],0,$inc);
  106. print("\n",$new);
  107. my $new1=substr($sortedarray[$ucount],0,$inc);
  108. print(" ",$new1);
  109. if($new eq $new1)
  110. {
  111. $upperlimit=$lcount-1;
  112. print("\n",$upperlimit);
  113. $mat=$inc-1;
  114. print("\n",$mat);
  115. splitter();
  116. }
  117. else
  118. {
  119. $ulimit--;
  120. $lcount++;
  121. $ucount++;
  122. print("\n",$lcount,"\n",$ucount,"\n",$ulimit);
  123. }
  124. }
  125. $mat=$inc-1;
  126. print $mat;
  127. splitter();
  128. }
  129. }
  130. else
  131. {
  132. $inc++;
  133. print $inc;
  134. unless(($count) == $upperlimit)
  135. {
  136. $count=$lowerlimit;
  137. func();
  138. }
  139. }
  140. }
  141. else
  142. {
  143. $upperlimit=$count;
  144. func();
  145. }
  146. }
  147. func();
  148.  
Runtime error #stdin #stdout 0s 4724KB
stdin
Standard input is empty
stdout
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
7All the words are parsed4
7
turnsponselmignbelalrtalrtal
7All the words are parsed