UVa 101 - The Blocks Problem

101 - The Blocks Problem

 * http://online-judge.uva.es/p/v1/101.html

Summary
This is a simple Simulation problem. There should be more than enough time to pass.

Explanation
Things to think about include deciding what data structure to use and how to find where each block is. Since the main operations are deletion, insertion, and splicing, linked lists are a good choice. You can also use a lookup table for keeping track of where each block is, as long as you update it for each operation.

In this problem using modularity really helps; create a function for each of the different move/pile operations and one other for printing. This way you can make sure each of the individual operations is done correctly instead of trying to find a bug amongst your whole program.

Gotcha's
Watch out for the illegal commands: those with a and b in the same stack.

Input
Input Here

Output
Output Here