Ideas: pointer and malloc
There are 10 tables (indexed from 0 to 9) and no cards on them initially.
Given a command S, Sakura has to follow the instructions below:
(1) print: print the status of each table with the format :"table_idx: cards_on_the tables\n", e.g. "0: 1 3 3 4 5\n".
Note that if there are no cards, print "No card".
(2) all num len : Place len cards on each table, and the value on each card is num .
For example, the instruction "all 3 4" changes the status of each table to "table_idx: 3 3 3 3\n";
(3)
place table_idx len
For example, the instruction will be like:
place 2 3
3 2 1
And the status of Table_2 will become:
2: 3 2 1
Note that if there are cards already on the target table, the status will be overridden.
(4) swap table_a table_b: Swap the cards on table_a and table_b.
For example:
If the origin status of table 0 and table 1 are:
0: 1 2 3
1: 4 5 6
after "swap 0 1", the status of the two tables become:
0: 4 5 6
1: 1 2 3
This instruction is valid even if one of the tables is empty.
(5) clear: Clean all the tables.
(6) exit: terminates
hint. You can use pointer array to record each table.
Input
Commands separated by a newline character.Note that:
1 <= the value of each card <= 13
1 <= number of cards on each table <= 10000
Output
Status of each table.