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