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