【NOIP2017提高A组模拟8.10】文本编辑器

37 篇文章 0 订阅
21 篇文章 0 订阅

Description

这里写图片描述

Input

第一行是初始内容
之后按照题目要求

Output

对于每个命令,按照要求输出

Sample Input

goodykc
11
I R u
I R l

L
L
L
L
R
D R
< R
D R
S

Sample Output

T
T
T
T
T
T
T
F
T
T
goodluck

Solution

毒瘤
显然可以用splay做,但是只有90分
100分必须线性做法
有一个比较简单的做法
左指针左边的维护一个栈,有指针右边的维护一个栈
中间的维护一个双向队列
是否翻转直接打标记
如果左指针跑到了有指针右边,就直接交换指针,并打交换标记
这不是唯一做法,但应该是细节最少最好做的做法

Code

#include<cstdio>
#include<algorithm>
#include<cstring>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define N 5010000
using namespace std;
char s[N];
int a[N*2],b[2][N*2],re=0,rev=0,tot[2],l,r;
int main()
{
    scanf("%s\n",s+1);
    int n=strlen(s+1);
    fo(i,1+N,n+N) a[i]=s[i-N];
    l=1+N,r=n+N;
    int ac;scanf("%d\n",&ac);
    for(;ac;ac--)
    {
        char ch;scanf("%c",&ch);
        if(ch=='<')
        {
            char W;scanf(" %c\n",&W);
            int y=W=='L'?0:1;
            if(re) y=1-y;
            if(y==0)
            {
                if(tot[y]>0) 
                {
                    if(rev) a[++r]=b[0][tot[0]],tot[0]--;
                    else a[--l]=b[0][tot[0]],tot[0]--;
                    printf("T\n");
                }
                else printf("F\n");
            }
            else
            {
                if(tot[y]<n)
                {
                    if(tot[1]+tot[0]==n) re^=1;
                    else 
                    {
                        if(rev) b[1][++tot[1]]=a[l++];
                        else b[1][++tot[1]]=a[r--];
                    }
                    printf("T\n");
                }
                else printf("F\n");
            }
        }
        if(ch=='>')
        {
            char W;scanf(" %c\n",&W);
            int y=W=='L'?0:1;
            if(re) y=1-y;
            if(y==0)
            {
                if(tot[y]<n) 
                {
                    if(tot[1]+tot[0]==n) re^=1;
                    else
                    {
                        if(rev) b[0][++tot[0]]=a[r--];
                        else b[0][++tot[0]]=a[l++];
                    }
                    printf("T\n");
                }
                else printf("F\n");
            }
            else
            {
                if(tot[y]>0)
                {
                    if(rev) a[--l]=b[1][tot[1]],tot[1]--;
                    else a[++r]=b[1][tot[1]],tot[1]--;
                    printf("T\n");
                }
                else printf("F\n");
            }
        }
        if(ch=='I')
        {
            char W,c;scanf(" %c %c\n",&W,&c);
            int y=W=='L'?0:1;
            if(re) y=1-y;
            if(y==0)
            {
                tot[0]++;b[0][tot[0]]=c;
            }
            else
            {
                if(rev) a[--l]=c;
                else a[++r]=c;
            }
            n++;
            printf("T\n");
        }
        if(ch=='D')
        {
            char W,c;scanf(" %c\n",&W);
            int y=W=='L'?0:1;
            if(re) y=1-y;
            if(y==0)
            {
                if(r-l+1) 
                {
                    if(rev) r--;
                    else l++;
                    n--;
                    printf("T\n");
                }
                else printf("F\n");
            }
            else
            {
                if(tot[1]>0)
                {
                    tot[1]--;
                    printf("T\n");
                }
                else printf("F\n");
            }

        }
        if(ch=='R')
        {
            scanf("\n");
            if(!re) rev^=1,printf("T\n");
            else printf("F\n");
        }
        if(ch=='S')
        {
            scanf("\n");
            fo(i,1,tot[0]) printf("%c",b[0][i]);
            if(rev) fd(i,r,l) printf("%c",a[i]);
            else fo(i,l,r) printf("%c",a[i]);
            fd(i,tot[1],1) printf("%c",b[1][i]);
            printf("\n");
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值