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