Assume you have a set of cards laid out in an n by m grid (n rows of m columns each). Some are face up, and others are face down. We can collapse the grid into a single pile by using a series of flips, each of which is one of the four following types: Top Flip: Here the cards in the top row are flipped over onto the corresponding cards on the row beneath them. Note that if a card is face up in the top row, it becomes face down after the flip, and vice versa. If the top row contains one or more piles of cards, each entire pile is flipped over like a stack of pancakes as it is moved to the lower row. Note: Conceptually, we think of flipping the ENTIRE stack at once; what actually happens is that each card in the stack gets flipped one at a time, until that stack has no cards left.
Instruction
Input: Each test case will start with a line containing two positive integers n m indicating the number of rows and columns in the grid. There will be a space between n and m. After this will come n rows of m strings indicating each card’s number and its orientation. (the first row is the top row and the first value in each row is the leftmost card.) Each string will be of the format OSV, where: O is the orientation: either ‘U’ for “face-Up”, or ‘F’ for “face-Down” S is the suit: one of ‘C’, ‘D’, ‘H’, ‘S’ for “Clubs”, “Diamonds”, “Hearts”, or “Spades”, respectively V is the face Value: one of ‘2’, … ‘9’, ‘T’ (ten), ‘J’ (Jack), ‘Q’ (queen), ‘K’ (King), or ‘A’ (Ace) Thus, “USA” indicates “Ace of spaces, face-up”, and “DC3” represents “3 of Clubs, face-down” You will have to (A) make sure that each OSV string is valid, and then (B) convert each to an integer in the range of -52 to +52, representing the four suits and 13 values, with the sign representing the orientation. Zero will not be used. If a string is not valid, your program must end. Immediately, with no error message (a rather user-unfriendly and heavy-handed way of handling errors, but this program isn’t necessarily about the input’s validity so much as it is about processing the stacks. Your input must accept upper- or lower-case characters(card identification strings are not case-sensitive). After these n rows there will be one more line containing n + m – 2 characters indicating the order in which to apply the flips to the grid. Each character will be either ‘T’, ‘B’, ‘L’ or ‘R’ corresponding to a top, bottom, left or right flip. All flip sequences will be legal, i.e., you won’t be asked to do more than n – 1 top and bottom flips or m – 1 left and right flips. You are not responsible for making sure that the flip directions are one of TBLR – I won’t test your code with an illegal flip direction. The maximum value for n and m is 20. A line containing two zeros will terminate input. Obviously, if m * n is > 52, it will require more than one deck of cards. Repeated cards should be a non-issue for your program
The post Assume you have a set of cards laid out in an n by m grid (n rows of m columns each). Some are face up, and others are face down. We can collapse the grid into a single pile by using a series of flips, each of which is one of the four following types: Top Flip: Here the cards in the top row are flipped over onto the corresponding cards on the row beneath them. Note that if a card is face up in the top row, it becomes face down after the flip, and vice versa. If the top row contains one or more piles of cards, each entire pile is flipped over like a stack of pancakes as it is moved to the lower row. Note: Conceptually, we think of flipping the ENTIRE stack at once; what actually happens is that each card in the stack gets flipped one at a time, until that stack has no cards left. appeared first on superioressaypapers.