The very last flip performed will result in one pile of cards ― some face up, some face down. For example, suppose Bobby deals out 5 cards (numbered 1 through 5) with cards 1 through 3 initially face up and cards 4 and 5 initially face down. If Bobby performs 2 right flips, then 2 left flips, the pile will be (from top to bottom) a face down 2, a face up 1, a face up 4, a face down 5, and a face up 3.
Now Bobby is very sharp and you can ask him what card is in any position and he can tell you!!! You will write a program that matches Bobby’s amazing feat.
Input Each test case will consist of 4 lines. The first line will be a positive integer n (2 ≤ n ≤ 100) which is the number of cards laid out. The second line will be a string of n characters. A character U indicates the corresponding card is dealt face up and a character D indicates the card is face down. The third line is a string of n - 1 characters indicating the order of the flips Bobby performs. Each character is either R, indicating a right flip, or L, indicating a left flip. The fourth line is of the form m q1 q2 . . . qm, where m is a positive integer and 1 ≤ qi ≤ n. Each qi is a query on a position of a card in the pile (1 being the top card, n being the bottom card). A line containing 0 indicates end of input.
Output Each test case should generate m + 1 lines of output. The first line is of the form
Pile twhere t is the number of the test case (starting at 1). Each of the next m lines should be of the form
Card qi is a face up k.or
Card qi is a face down k.accordingly, for i = 1, .., m, where k is the number of the card.
For instance, in the above example with 5 cards, if qi = 3, then the answer would be
Card 3 is a face up 4.
Sample Input
5 UUUDD RRLL 5 1 2 3 4 5 10 UUDDUUDDUU LLLRRRLRL 4 3 7 6 1 0
Sample Output
Pile 1 Card 1 is a face down 2. Card 2 is a face up 1. Card 3 is a face up 4. Card 4 is a face down 5. Card 5 is a face up 3. Pile 2 Card 3 is a face down 1. Card 7 is a face down 9. Card 6 is a face up 7. Card 1 is a face down 5.
思路:R操作就是把最右边的一堆牌放到次右边并改变每一张牌的方向,L操作就是把最左边的一堆牌放到次左边并改变每一张牌的方向。注意:每一对牌的最上面一个先取出,因此,直接用栈来模拟比较方便。
#include#include using namespace std; struct S{ char s; int num; }que[101]; stack a[101];//用栈模拟 int main() { int n,m,i,top,bottom,casenum=1; char c[101]; struct S temp; while(~scanf("%d",&n) && n) { top=1; bottom=n; scanf("%s",c); for(i=1;i<=n;i++) { while(!a[i].empty())//读入数据前先清栈 { a[i].pop(); } temp.s=c[i-1]; temp.num=i; a[i].push(temp);//把数据压栈 } scanf("%s",c); for(i=1;i