Google code Jam qualification round 2010 – Reverse Words solution
Below is the problem taken from GC jam qualification round 2010:-
Given a list of space separated words, reverse the order of the words. Each line of text contains
words. A line will only consist of letters and space characters. There will be exactly one space character between each pair of consecutive words.
The first line of input gives the number of cases, N.
N test cases follow. For each test case there will a line of letters and space characters indicating a list of space separated words. Spaces will not appear at the start or end of a line.
For each test case, output one line containing “Case #x: ” followed by the list of words in reverse order.
N = 5
1 ≤ L ≤ 25
N = 100
1 ≤ L ≤ 1000
Below is a solution to the problem using node.js. To run this program. install nodejs from here. From the command line, go to the directory where this file is saved, say for eg. readFile.js and type in node readFile.js from the command prompt. It will output data to a file called output.txt and will also print it on screen.
Link to the problem is here. 2 set of input files (large and small are as below)