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. $upperlimit=$count;
  66. $count = $lowerlimit;
  67. $inc++;
  68. print $inc;
  69. func();
  70. }
  71. else
  72. {
  73. last;
  74. }
  75. }
  76. print("\n",$base," ",$match);
  77. $count++;
  78. if($base ne $match)
  79. {
  80. if(($count-1) == $lowerlimit)
  81. {
  82. my $lcount=$count;
  83. my $ucount=$count+1;
  84. if($ucount==scalar(@sortedarray))
  85. {
  86. $upperlimit=$count;
  87. $mat=$inc-1;
  88. splitter();
  89. }
  90. else
  91. {
  92. my $ulimit=$upperlimit;
  93. print("\n",$lcount,"\n",$ucount,"\n",$ulimit);
  94. while($ulimit>=$count)
  95. {
  96. my $new=substr($sortedarray[$lcount],0,$inc);
  97. print("\n",$new);
  98. my $new1=substr($sortedarray[$ucount],0,$inc);
  99. print(" ",$new1);
  100. if($new eq $new1)
  101. {
  102. $upperlimit=$lcount-1;
  103. print("\n",$upperlimit);
  104. $mat=$inc-1;
  105. print("\n",$mat);
  106. splitter();
  107. }
  108. else
  109. {
  110. $ulimit--;
  111. $lcount++;
  112. $ucount++;
  113. print("\n",$lcount,"\n",$ucount,"\n",$ulimit);
  114. }
  115. }
  116. $mat=$inc-1;
  117. print $mat;
  118. splitter();
  119. }
  120. }
  121. else
  122. {
  123. $inc++;
  124. print $inc;
  125. unless(($count) == $upperlimit)
  126. {
  127. $count=$lowerlimit;
  128. func();
  129. }
  130. }
  131. }
  132. else
  133. {
  134. $upperlimit=$count;
  135. func();
  136. }
  137. }
  138. func();
  139.  
Runtime error #stdin #stdout 0.01s 5364KB
stdin
Standard input is empty
stdout
Standard output is empty