Reversing Card Segments
InterviewTime limit1sMemory limit256 MB
Reverse ten given segments of a 20-card row that starts in order and print the final arrangement.
- Level
Easy1 of 10
- Topics
- Array, Simulation
- Solved
- No attempts yet
Problem
Twenty cards, each carrying one number from 1 to 20, lie in a row in ascending order. Positions are numbered 1 to 20 from the left.
Given a segment with , put the cards from position to position back in the reverse of their current order.
Suppose the segment is given in the starting state. Cards 5, 6, 7, 8, 9, 10 at positions 5 to 10 become 10, 9, 8, 7, 6, 5, and the whole row looks like this.
If the segment is given next, cards 6, 5, 11, 12, 13 at positions 9 to 13 become 13, 12, 11, 5, 6, and the whole row looks like this.
Ten segments are given for the twenty cards that start in ascending order. Apply the reversals one after another in the given order and report the final arrangement.
Input
Ten lines each hold one segment. Line holds the start position and the end position of the -th segment, separated by a space, with .
Output
Print the arrangement after all ten segments have been applied in the given order, on one line. Write the card numbers at positions 1 to 20, separated by single spaces.