Data in spreadsheets are stored in cells, which are organized in rows (r) and columns (c). Some operations on spreadsheets can be applied to single cells (r,c), while others can be applied to entire rows or columns. Typical cell operations include inserting and deleting rows or columns and exchanging cell contents. Some spreadsheets allow users to mark collections of rows or columns for deletion, so the entire collection can be deleted at once. Some (unusual) spreadsheets allow users to mark collections of rows or columns for insertions too. Issuing an insertion command results in new rows or columns being inserted before each of the marked rows or columns. Suppose, for example, the user marks rows 1 and 5 of the spreadsheet on the left for deletion. The spreadsheet then shrinks to the one on the right. ↘123456789 1 22 55 66 77 88 99 10 12 14 2 2 24 6 8 22 12 14 16 18 3181920212223242526 4242526672269707177 5687879802225282930 6161211102256575859 7333435362238394041 If the user subsequently marks columns 3, 6, 7, ↘12345 ↘ 1 2 3 4 5 1 2 3 4 5 6 7 8 9 2 24 18 19 24 25 16 12 33 34 6 8 22 12 14 16 18 20 21 22 23 24 25 26 26 67 22 69 70 71 77 11 10 22 56 57 58 59 35 36 22 38 39 40 41 1 2 24 2 18 19 3 24 25 4 16 12 5 33 34 8 22 16 21 22 25 67 22 71 10 22 58 36 22 40 and 9 for deletion, the spreadsheet shrinks to this. If the user marks rows 2, 3 and 5 for insertion, the spreadsheet grows to the one on the left. If the user then marks column 3 for insertion, the spreadsheet grows to the one in the middle. Finally, if the user exchanges the contents of cell (1,2) and cell (6,5), the spreadsheet looks like the one on the right. ↘12345 ↘123456↘123456 1 224 82216 1 224 82216 1 222 31819212225 31819 212225 3 444 52425672271 52425 672271 5 61612102258 61612 102258 6 777 83334362240 83334 362240 8 222 18 19 24 25 16 12 33 34 8 22 16 21 22 25 67 22 71 10 24 58 36 22 40 You must write tracking software that determines the final location of data in spreadsheets that result from row, column, and exchange operations similar to the ones illustrated here.
2/3 Input
The input consists of a sequence of spreadsheets, operations on those spreadsheets, and queries about them. Each spreadsheet definition begins with a pair of integers specifying its initial number of rows (r) and columns (c), followed by an integer specifying the number (n) of spreadsheet operations. Row and column labeling begins with 1. The maximum number of rows or columns of each spreadsheet is limited to 50. The following n lines specify the desired operations.
An operation to exchange the contents of cell (r1,c1) with the contents of cell (r2,c2) is given by: EXr1 c1 r2 c2
The four insert and delete commands—DC (delete columns), DR (delete rows), IC (insert columns), and IR (insert rows) are given by:
3/3 Sample Output Spreadsheet #1 Cell data in (4,8) moved to (4,6) Cell data in (5,5) GONE Cell data in (7,8) moved to (7,6) Cell data in (6,5) moved to (1,2)