Flipper
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 301 Accepted Submission(s): 198
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.
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.
5 UUUDD RRLL 5 1 2 3 4 5 10 UUDDUUDDUU LLLRRRLRL 4 3 7 6 1 0
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.
#include <stack>
#include <stdio.h>
#include <string.h>
#include <cstring>
#include <iostream>
using namespace std;
using namespace std;
struct fuck
{
int num;
char ud;
} card[105],temp;
char cards[105];
char flip[105];
stack<fuck> s[105];
int main()
{
int t=0,m,n,left,right,p,i;
while(scanf("%d",&n)&&n!=0)
{
t++;
//gets(cards);
//gets(flip);
scanf("%s",cards);
scanf("%s",flip);
for(i=0; i<=n; i++)
{
while(s[i].empty()!=true)
{
s[i].pop();
}
}
for(i=1; i<=n; i++)
{
temp.num=i;
temp.ud=cards[i-1];
s[i].push(temp);
}
left=1;
right=n;
for(i=1; i<=n-1; i++)
{
if(flip[i-1]=='R')
{
while(s[right].empty()!=true)
{
temp=s[right].top();
if(temp.ud=='U')
{
temp.ud='D';
}
else
{
temp.ud='U';
}
s[right-1].push(temp);
s[right].pop();
}
right--;
}
else
{
while(s[left].empty()!=true)
{
temp=s[left].top();
if(temp.ud=='U')
{
temp.ud='D';
}
else
{
temp.ud='U';
}
s[left+1].push(temp);
s[left].pop();
}
left++;
}
}
i=1;
while(s[left].empty()!=true)
{
card[i].num=s[left].top().num;
card[i].ud=s[left].top().ud;
s[left].pop();
i++;
}
printf("Pile %d\n",t);
scanf("%d",&m);
for(i=1; i<=m; i++)
{
scanf("%d",&p);
if(card[p].ud=='U')
{
printf("Card %d is a face up %d.\n",p,card[p].num);
}
else
{
printf("Card %d is a face down %d.\n",p,card[p].num);
}
}
}
}