Saturday, May 31, 2014

Reverse the words in a statement

Script

#!/usr/bin/perl

print ("Enter a statement of your choice:\n");
print ("Press Ctrl D when you are done:\n");

@input = <STDIN>;
chop (@input);

$current_line = 1;

while ($current_line <= @input)
        {
        @words = split(/ /, $input[$current_line - 1]);
        @words = reverse(@words);
        @input[$current_line - 1] = join(" ", @words, "\n");
        $current_line++;
        }

@input = reverse(@input);
print ("\n");
print (@input);


Execution

Enter a statement of your choice:
Press Ctrl D when you are done:
The best Unix administrators are those who keep learning continuously.

continuously. learning keep who those are administrators Unix best The





Enter a statement of your choice:
Press Ctrl D when you are done:
The problem is not the real problem.  The real problem is in expecting no problems and in thinking that having a problem is a big problem.  There lies the problem.

problem. the lies There  problem. big a is problem a having that thinking in and problems no expecting in is problem real The  problem. real the not is problem The




Enter a statement of your choice:
Press Ctrl D when you are done:
Adelaide Test 2003. India versus Australia. Australia 556. India, through a mammoth partnership of 303 between Dravid and Laxman, recover from 85 for 4 to 477 for 7. Dravid is on strike on 199. The first ball of the last and 90th over of Day three is being bowled. Dravid hits the ball to deep cover. He has two choices: a) take a single, complete his double century but expose the tailender Anil Kumble to five deliveries before the end of the day's play b) refuse to take the easy single, defend the next five balls or risk taking a single off the last ball of the day thereby protecting Anil Kumble. Dravid refuses the single that would take him to 200, and cannot force the last ball of the day for a single. Stranded on 199 not out overnight and have to endure a sleepless night. Never mind; team interests come first, ahead of personal milestones. That's Dravid for you !!!


!!! you for Dravid That's milestones. personal of ahead first, come interests team mind; Never night. sleepless a endure to have and overnight out not 199 on Stranded single. a for day the of ball last the force cannot and 200, to him take would that single the refuses Dravid Kumble. Anil protecting thereby day the of ball last the off single a taking risk or balls five next the defend single, easy the take to refuse b) play day's the of end the before deliveries five to Kumble Anil tailender the expose but century double his complete single, a take a) choices: two has He cover. deep to ball the hits Dravid bowled. being is three Day of over 90th and last the of ball first The 199. on strike on is Dravid 7. for 477 to 4 for 85 from recover Laxman, and Dravid between 303 of partnership mammoth a through India, 556. Australia Australia. versus India 2003. Test Adelaide


No comments:

Post a Comment