加入收藏 | 设为首页 | 会员中心 | 我要投稿 辽源站长网 (https://www.0437zz.com/)- 云专线、云连接、智能数据、边缘计算、数据安全!
当前位置: 首页 > 服务器 > 安全 > 正文

【HDU 3328】【数据结构】Flipper

发布时间:2021-03-31 11:36:13 所属栏目:安全 来源:网络整理
导读:? ? ? ? 就是一个翻牌子的问题,写的略繁琐,因为只是实验室水题,所以不优化了,L是从最左翻面并且覆盖到第二堆上,以此类推,模拟就好。 #include "stdio.h"#include "stack"#include "queue"using namespace std;int main(int argc,char const *argv[]){

? ? ? ?


就是一个翻牌子的问题,写的略繁琐,因为只是实验室水题,所以不优化了,L是从最左翻面并且覆盖到第二堆上,以此类推,模拟就好。


#include "stdio.h"
#include "stack"
#include "queue"
using namespace std;
int main(int argc,char const *argv[])
{
    int n;
    int cas=1;
    while(~scanf("%d",&n) && n)
    {
        getchar();
        int lnum=1;
        int rnum=n;
        int Poker[105];
        stack <int> s1,s2,s3;
        char sta,ope;
        for (int i = 1; i <= n; ++i)
        {
            scanf("%c",&sta);
            if(sta=='D')
                Poker[i]=0;
            else
                Poker[i]=1;
        }
        getchar();
        s1.push(1);
        s2.push(n);

        for (int i = 1; i < n; ++i)
        {
            scanf("%c",&ope);
            if(ope=='L')
            {
                for (int j = 1; j <= lnum; ++j)
                {
                    if(Poker[j])
                        Poker[j]=0;
                    else
                        Poker[j]=1;
                }
                lnum++;
                if(lnum==rnum)
                {
                    while(!s2.empty())
                    {
                        int temp2=s2.top();
                        s2.pop();
                        s1.push(temp2);
                    }
                    while(!s1.empty())
                    {
                        int temp1=s1.top();
                        s1.pop();
                        s3.push(temp1);
                    }
                    break;
                }
                queue <int> temp;
                temp.push(lnum);
                while(!s1.empty())
                {
                    int temp1=s1.top();
                    s1.pop();
                    temp.push(temp1);
                }
                while(!temp.empty())
                {
                    int temp1=temp.front();
                    temp.pop();
                    s1.push(temp1);
                }
            }
            if(ope=='R')
            {
                for (int j = n; j >= rnum; --j)
                {
                    if(Poker[j])
                        Poker[j]=0;
                    else
                        Poker[j]=1;
                }
                rnum--;
                if(lnum==rnum)
                {
                    while(!s1.empty())
                    {
                        int temp1=s1.top();
                        s1.pop();
                        s2.push(temp1);
                    }
                    while(!s2.empty())
                    {
                        int temp2=s2.top();
                        s2.pop();
                        s3.push(temp2);
                    }
                    break;
                }
                queue <int> temp;
                temp.push(rnum);
                while(!s2.empty())
                {
                    int temp2=s2.top();
                    s2.pop();
                    temp.push(temp2);
                }
                while(!temp.empty())
                {
                    int temp2=temp.front();
                    temp.pop();
                    s2.push(temp2);
                }
            }
        }
        printf("Pile %dn",cas++);
        int num;
        int a[1000];
        int b[1000];
        int bnum=1;
        while(!s3.empty())
        {
            int temp=s3.top();
            b[bnum++]=temp;
            s3.pop();
        }
        scanf("%d",&num);
        for (int i = 0; i < num; ++i)
        {
            scanf("%d",&a[i]);
        }
        for (int i = 0; i < num; ++i)
        {
            printf("Card %d is a face ",a[i]);
            if(Poker[b[a[i]]])
                printf("up ");
            else
                printf("down ");
            printf("%d.n",b[a[i]]);
        }


        
    }
    return 0;
}

(编辑:辽源站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读