2015北京赛区网络赛模拟题

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define rd(x) scanf("%d",&x)
#define rdd(x,y) scanf("%d%d",&x,&y)
#define rddd(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define rds(s) scanf("%s",s)
#define rep(i,n) for(int i=0;i<n;i++)
#define LL long long
const int N = 1e4+10;
const int M=5e5+10;
const int inf=1e9;
const double esp=1e-8;
const int MOD=1e9+7;
int n,m,k;
struct node{
    char c;
    node*f,*b;
    node(){

    }
    node(char x){
        c=x;
        f=b=0;
    }
};
struct Edit{
    int len;
    node *cp,*p,*cur_cp,*end_cp,*tmp;
    node *start;
    char clip[N];
    int clip_len;
    int copy_status;
    int switch_status;
    int dir;
    void init(){
        start=new node('*');
        cp=start;
        len=0;
        copy_status=0;
        switch_status=0;
        clip_len=0;
        cur_cp=end_cp=0;
    }
    void goLeft(){
        if(cp->c!='*') {
            cp=cp->f;
            dir--;
        }
    }
    void goRight(){
        if(cp->b) {
            cp=cp->b;
            dir++;
        }
    }
    void link(node*x,node*y){
        if(x) x->b=y;
        if(y) y->f=x;
    }
    void insert(char x){
   // cout<<cp->c<<endl;
        if(len>=n) return;
        p=new node(x);
        link(p,cp->b);
        link(cp,p);
        cp=p;
        len++;
    }
    void rewrite(char x){
        if(cp->b==0){
            insert(x);
        }else{
            cp->b->c=x;
            cp=cp->b;
        }
    }
    bool isInsert(){
        return switch_status==0;
    }
    void putIn(char x){
         if(isCopying()) end_copy();
        if(isInsert()) insert(x);
        else rewrite(x);
    }
    void del(){
        if(cp->b){
            link(cp,cp->b->b);
            len--;
        }
    }
    void bel(){
        if(cp->c=='*') return;
        p=cp->f;
        link(p,cp->b);
        cp=p;
        len--;
    }
    void end_copy(){
        copy_status=0;
    }
    void swi(){
         switch_status^=1;
    }
    bool isCopying(){
        return copy_status==1;
    }
    void updateClip(){
        if(dir<0) swap(cur_cp,end_cp);
        p=cur_cp;
        clip_len=0;
        while(p!=end_cp){
            p=p->b;
            clip[clip_len++]=p->c;
        }
    }
    void delClip(){
        end_cp=cp;
        if(dir<0) swap(cur_cp,end_cp);
        len-=abs(dir);
        link(cur_cp,end_cp->b);
    }
    void cop(){
       if(isCopying()){
          end_cp=cp;
          updateClip();
       }else{
          cur_cp=cp;
          dir=0;
       }
    }
    void paste(){
        for(int i=0;i<clip_len;i++)
        putIn(clip[i]);
    }
    void print(){
  //  cout<<len<<endl;
        if(len==0){
            puts("NOTHING");
            return;
        }
        p=start;
        while(p->b){
            p=p->b;
            printf("%c",p->c);
        }
        puts("");
    }
    void L(){
        goLeft();
    }
    void R(){
        goRight();
    }
    void D(){
        if(isCopying()) {
            delClip();
            end_copy();
        }
        else del();
    }
    void B(){
     if(isCopying()) end_copy();
        bel();
    }
    void V(){
        paste();
    }
    void S(){
        if(isCopying()) end_copy();
        switch_status^=1;
    }
    void C(){
        if(isCopying()){
            end_cp=cp;
            updateClip();
        }else{
            cur_cp=cp;
            dir=0;
        }
        copy_status^=1;
    }
}edit;
int main()
{
#ifndef ONLINE_JUDGE
   freopen("aaa","r",stdin);
#endif
    int T,q;
    rd(T);
    char input[N],ch;
    while(T--){
        scanf("%d%s",&n,input);
        edit.init();
        int len=strlen(input);
        for(int i=0;i<len;i++){
            ch=input[i];
            if(ch=='L') edit.L();
            else if(ch=='R') edit.R();
            else if(ch=='D') edit.D();
            else if(ch=='B') edit.B();
            else if(ch=='S') edit.S();
            else if(ch=='C') edit.C();
            else if(ch=='V') edit.V();
            else if(ch>='a' && ch<='z') edit.putIn(ch);

           // cout<<ch<<": ";
            //edit.print();
        }
        edit.print();


    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值