Description
Code Jam to I/O for Woman 2014 (1) Saturnalia (15 pts)
Problem (Simplified)
Caterina needs a computer program that reads a message and outputs it back, decorated with a box.
Input
The first line of the input gives the number of test cases, T. T lines follow. Each line contains a text message.
Output
For each test case, output four lines. The first one should contain “Case #x:”, where x is the test case number (starting from 1). The next 3 lines should contain the original message surrounded by a box of ‘+’, ‘-‘, and ‘|’ characters, with a space character added on each side of the message. See examples below for the exact formatting requirements. Pay special attention to the spaces.
Sample
Input:
1
2
3
4
5
6 5
Merry Saturnalia, Giovanni!
Equus, you're the best!
>Caballus, you try really hard!
>wOutput:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 Case #1:
+-----------------------------+
>| Merry Saturnalia, Giovanni! |
+-----------------------------+
>Case #2:
+-------------------------+
| Equus, you're the best! |
+-------------------------+
Case #3:
+--------------------------------+
| Caballus, you try really hard! |
>+--------------------------------+
Case #4:
>+-----+
| |
+-----+
Case #5:
+---+
| w |
+---+
Solution
We just need to output the required characters at the right position
1 | import java.util.*; |
Time Complexity: O(n) n is the length of the input string
Space Complexity: O(n)
Summary
- As the very first task of Code Jam to I/O, it is quite simple