您的位置:首页 > 理论基础 > 计算机网络

2015北京赛区网络赛模拟题

2015-09-20 19:03 393 查看
#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
;
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
,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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: