fork download
  1. use warnings;
  2. my @iparray=("qua","aqua","backwa","kkokoko");
  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.  
  24. print("\n",$temp);
  25.  
  26. while($temp>=$lowerlimit)
  27. {
  28. $word=substr($sortedarray[$temp],$mat,length($sortedarray[$temp]));
  29. if($word eq "")
  30. {
  31. push @oparray,"\\s";
  32. }
  33. else
  34. {
  35. push @oparray ,$word;
  36. }
  37.  
  38. $temp--;
  39. }
  40. print ("\n",@oparray);
  41. print("\n",$upperlimit);
  42. if(($upperlimit)==(scalar(@sortedarray)-1))
  43. {
  44. die "Terminated ";
  45. #print $upperlimit+1;
  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. print "All the words are parsed";
  59. sub func
  60. {
  61. if (defined $sortedarray[$count])
  62. {
  63. $base=substr($sortedarray[$count],0,$inc);
  64. }
  65. if (defined $sortedarray[$count+1])
  66. {
  67. $match=substr($sortedarray[$count+1],0,$inc) ;
  68. }
  69. else
  70. {
  71. if (defined $sortedarray[$count-1])
  72. {
  73. $s=substr($sortedarray[$count-1],0,$inc);
  74. }
  75. if($s eq $base)
  76. {
  77. $upperlimit=$count;
  78. $count = $lowerlimit;
  79. $inc++;
  80. #print $inc;
  81. func();
  82. }
  83. else
  84. {
  85. die"Oh my god";
  86. }
  87. }
  88. print("\n",$base," ",$match);
  89. $count++;
  90. if($base ne $match)
  91. {
  92. if(($count-1) == $lowerlimit)
  93. {
  94. my $lcount=$count;
  95. my $ucount=$count+1;
  96. if($ucount>=scalar(@sortedarray))
  97. {
  98. $upperlimit=$count;
  99. $mat=$inc-1;
  100. splitter();
  101. }
  102. else
  103. {
  104. my $ulimit=$upperlimit;
  105. print("\n",$lcount,"\n",$ucount,"\n",$ulimit);
  106. while($ulimit>=$count)
  107. {
  108. my $new=substr($sortedarray[$lcount],0,$inc);
  109. print("\n",$new);
  110. my $new1=substr($sortedarray[$ucount],0,$inc);
  111. print(" ",$new1);
  112. if($new eq $new1)
  113. {
  114. $upperlimit=$lcount-1;
  115. print("\n",$upperlimit);
  116. $mat=$inc-1;
  117. print("\n",$mat);
  118. splitter();
  119. }
  120. else
  121. {
  122. $ulimit--;
  123. $lcount++;
  124. $ucount++;
  125. print("\n",$lcount,"\n",$ucount,"\n",$ulimit);
  126. }
  127. }
  128. $mat=$inc-1;
  129. print $mat;
  130. splitter();
  131. }
  132. }
  133. else
  134. {
  135. $inc++;
  136. print $inc;
  137. unless(($count) == $upperlimit)
  138. {
  139. $count=$lowerlimit;
  140. func();
  141. }
  142. }
  143. }
  144. else
  145. {
  146. $upperlimit=$count;
  147. func();
  148. }
  149. }
  150. func();
  151.  
Runtime error #stdin #stdout 0s 4724KB
stdin
Standard input is empty
stdout
All the words are parsed
a b
1
2
0
b k
2
3
0
k q