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;
  45. $count=$lowerlimit;
  46. $inc=1;
  47. func();
  48. }
  49. }
  50. }
  51. sub func
  52. {
  53. $base=substr($sortedarray[$count],0,$inc);
  54. if (defined $sortedarray[$count+1])
  55. {
  56. $match=substr($sortedarray[$count+1],0,$inc) ;
  57. }
  58. else
  59. {
  60. $count = $lowerlimit;
  61. $inc++;
  62. print $inc;
  63. #func();
  64. }
  65. print("\n",$base," ",$match);
  66. $count++;
  67. if($base ne $match)
  68. {
  69. if(($count-1) == $lowerlimit)
  70. {
  71. $mat=$inc-1;
  72. print $mat;
  73. splitter();
  74. }
  75. else
  76. {
  77. $inc++;
  78. print $inc;
  79. unless(($count) == $upperlimit)
  80. {
  81. $count=$lowerlimit;
  82. func();
  83. }
  84. }
  85. }
  86. else
  87. {
  88. $upperlimit=$count;
  89. func();
  90. }
  91. }
  92. func();
  93.  
Runtime error #stdin #stdout 0s 4724KB
stdin
Standard input is empty
stdout
a p0
p p
p p
p r2
pa pi1ictureickack
p r02
r r3
 r2ictureickack\stAll the words are parsed