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