2014 Mock CCC by Alex and Timothy

Problem J2: Rope Unfolding

Alice's love potion failed because Bob overdosed. Now, her new tactic is to impress Bob. Bob is a computer scientist who specializes in ropes. In computer science, a rope is a data structure used for efficiently manipulating strings. Bob has a rope of characters. However, it's too long to fit in his pocket, so he folds it into N segments. Each fold is at a letter which is not the last. The fold takes the rest of the rope after that letter, reverses it, and puts it above the current letter. For example, the rope "ABRACADABRA", when folded "AB|RACA|DAB|RA", yields:

 AR
DAB
ACAR
  AB

Alice notices that Bob often gets a headache pulling the rope out of his pocket and spending a long time untangling it. She concludes that if she finds a way to unfold it for Bob, Bob will be so impressed that he can't help but fall madly in love with her. You must write a program to help Alice!

Input Format

The first line of input will contain the positive integer N (1 ≤ N ≤ 100), the number of lines to follow. The next N lines each contain a segment of the folded rope.
The entire, unfolded rope will be no greater than 100 characters, and will only consist of uppercase letters from 'A' to 'Z'.

Output Format

The output should contain one line — the unfolded rope.

Sample Input 1

4
 AR
DAB
ACAR
  AB

Sample Output 1

ABRACADABRA

Sample Input 2

5
D
LRO
  W
  OL
 HEL

Sample Output 2

HELLOWORLD

All Submissions
Best Solutions


Point Value: 3
Time Limit: 2.00s
Memory Limit: 16M
Added: Feb 27, 2014
Author: Alex

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

2
CD
BA

Would both ABCD and BADC be accepted?

no, only BADC is accepted

Why isn't ABCD accepted? It doesn't say anywhere in the problem statement, that the last line of input goes from left to right.
The "help" says "You should always assume that any test case that is not explicitly forbidden by the problem statement can and will appear in the test data". So, I can't see why this can't be a valid test case.
RA
BADA
_RAC
_BA

Input:

4
---GH
--EF
-CD
AB

Output: ABCDEFGH

I think this relaxation would break a lot of solutions.

Isn't this illegal by the conditions of the problem statement?

Yes it is illegal

the output should be ABDCEFHG