题解:直接建n个栈,模拟过程即可……
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
int main(){
int n,n2,a,ar[105],cas=1;
bool rs[105];
char str[105];
while(scanf("%d",&n),n){
scanf("%s",str);
for(int i=0;i<n;i++)rs[i]=(str[i]=='U')?1:0;
int l=0,r=n-1;
stack st[105];
for(int i=0;i<n;i++)st[i].push(i);
scanf("%s",str);
for(int i=0;i<n-1;i++){
if(str[i]=='L'){
l++;
for(int j=0;j<l;j++)rs[j]=!rs[j];
while(!st[l-1].empty()){
st[l].push(st[l-1].top());
st[l-1].pop();
}
}else{
r--;
for(int j=n-1;j>r;j--)rs[j]=!rs[j];
while(!st[r+1].empty()){
st[r].push(st[r+1].top());
st[r+1].pop();
}
}
}
for(int i=0;i<n;i++){ar[i]=st[l].top();st[l].pop();}
printf("Pile %d\n",cas++);
scanf("%d",&n2);
while(n2--){
scanf("%d",&a);
printf("Card %d is a face ",a);
a--;
printf(rs[ar[a]]?"up ":"down ");
printf("%d.\n",ar[a]+1);
}
}
return 0;
}