fork download
  1. use warnings;
  2. my @iparray=("and","rat","picture","pick","pack");
  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. $temp--;
  35. }
  36. print @oparray;
  37. if($upperlimit==scalar(@sortedarray))
  38. {
  39. print "All the words are parsed";
  40. last;
  41. }
  42. else
  43. {
  44. $lowerlimit=$upperlimit+1;
  45. $count=$lowerlimit;
  46. $inc=1;
  47. func();
  48. }
  49. }
  50. }
  51. sub func
  52. {
  53. if(($count+1)>(scalar(@sortedarray)))
  54. {
  55. last;
  56. }
  57. $base=substr($sortedarray[$count],0,$inc);
  58. if (defined $sortedarray[$count+1])
  59. {
  60. $match=substr($sortedarray[$count+1],0,$inc) ;
  61. }
  62. else
  63. {
  64. $count = $lowerlimit;
  65. $inc++;
  66. print $inc;
  67. func();
  68. }
  69. print("\n",$base," ",$match);
  70. $count++;
  71. if($base ne $match)
  72. {
  73. if(($sortedarray[$count-1]) eq ($sortedarray[$lowerlimit]))
  74. {
  75. $mat=$inc-1;
  76. print $mat;
  77. splitter();
  78. }
  79. else
  80. {
  81. $inc++;
  82. unless (($count-1) == $upperlimit)
  83. {
  84. $count=$lowerlimit;
  85. func();
  86. }
  87. }
  88. }
  89. else
  90. {
  91. $upperlimit=$count;
  92. func();
  93. }
  94. }
  95. func();
  96.  
Success #stdin #stdout 0s 4724KB
stdin
Standard input is empty
stdout
a p0
p p
p p
p r