Programming Team: Practice Contest,
8-Feb-05: I/O
Mt Lebanon HS 2004-5
David Kosbie
Link to the Programming Team Home Page.
Part 1 of 2: This is a Full Contest. Work as teams. Good luck!
Note: you must start from a blank compiler (not EmptyProgram.java!).
For this contest, use the problem set from the official SRU 2002 Programming Contest.
Part 2 of 2: This is a Quick Contest. (though you may work as teams this time..)
Note: you must start from a blank compiler (not EmptyProgram.java!).
Q1. Read in lines full of words and numbers
separated by spaces and/or newlines, and ending with an end-of-file. Print
out the longest word and the largest number.
Sample Input:
hi 22 this is 3.4
some 105.8 sample data 6
Sample Output:
sample 105.8
Q2. Read in lines starting with a string
followed by space-separated integers (terminated by end-of-file). Print
out each line in sorted order, where the string dictates the sort order ("lo"
for low-to-high and "hi" for high-to-low). Note: you must
use java.util.Arrays.sort for this problem.
Sample Input:
hi 2 8 3 1 4
lo 2 8 3 1 4
lo 5 4
Sample Output:
8 4 3 2 1
1 2 3 4 8
4 5
Q3. Repeat Q2, only this time the numbers
are comma-separated, (though still preceded by a space after "hi" or "lo") and
you must use a "four-line" sort, not Arrays.sort.
Sample Input:
hi 2,8,3,1,4
lo 2,8,3,1,4
lo 5,4
Sample Output:
8 4 3 2 1
1 2 3 4 8
4 5
Q4. Read in expressions, one per line (until
end-of-file), of the form a op b op c ..., and print out the value
of the expressions, rounded to the nearest tenth, when the operators are applied
in left-to-right order (so 2+3*4 evaluates to 5*4 not 2+12). The operators
will be +, -, *, or /.
Sample Input:
1 + 2 * 1.5 - 4
1 / 3
Sample Output:
0.5
0.3
Q5. Read in words on lines (ending with
end-of-file) and print out the word on each line with the most spaces preceding
it.
Sample Input:
this is a test
this is also a test
Sample Output:
test
is