InsideOut
SRM 224 · 2004-12-22 · by vorthys
Problem Statement
Your printer has been infected by a virus and is printing gibberish. After staring at several printed pages for a while, you realize that it is printing every line inside-out. In other words, the left half of each line is being printed starting in the middle of the page and proceeding out toward the left margin. Similarly, the right half of each line is being printed starting at the right margin and proceeding in toward the middle of the page. For example, the line
THIS LINE IS GIBBERISHis being printed as
I ENIL SIHTHSIREBBIG SYour task is to unscramble a
Constraints
- line contains between 2 and 50 characters, inclusive.
- line contains an even number of characters.
- line contains only uppercase letters ('A'-'Z') and spaces (' ').
"I ENIL SIHTHSIREBBIG S" Returns: "THIS LINE IS GIBBERISH"
The example above.
"LEVELKAYAK" Returns: "LEVELKAYAK"
"H YPPAHSYADILO" Returns: "HAPPY HOLIDAYS"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" Returns: "MLKJIHGFEDCBAZYXWVUTSRQPON"
"RUT OWT SNEH HCNERF EERHTEGDIRTRAP A DNA SEVODELT" Returns: "THREE FRENCH HENS TWO TURTLEDOVES AND A PARTRIDGE"
Submissions are judged against all 58 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class InsideOut with a public method string unscramble(string line) · 58 test cases · 2 s / 256 MB per case