比赛 HAOI2009 模拟试题2 评测结果 AAAAWAWTTT
题目名称 可可的文本编辑器 最终得分 50
用户昵称 王瑞祥K 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-04-22 11:01:41
显示代码纯文本
program editor(input,output);
var
 a:array[1..2097152]of char;
 n,gb,len:longint;

procedure ini;
begin
 assign(input,'editor.in');assign(output,'editor.out');
 reset(input);rewrite(output);
 fillchar(a,sizeof(a),0);
 readln(n);
 gb:=1;
 len:=0;
end;

procedure ins(l:longint);
var i:longint;
begin
 for i:=len+l downto gb+l do a[i]:=a[i-l];
 for i:=gb to gb+l-1 do read(a[i]);
 len:=len+l;
 readln;
end;

procedure del(l:longint);
var i:longint;
begin
 for i:=gb to len-l do a[i]:=a[i+l];
 len:=len-l;
end;

procedure rot(l:longint);
var i,j:longint; ch:char;
begin
 i:=gb; j:=gb+l-1;
 while i<j do begin
  ch:=a[i];a[i]:=a[j];a[j]:=ch;
  inc(i);dec(j);
 end;
end;

procedure command;
var p,l,code:longint; com:char; st:string;
begin
 readln(st);
 p:=pos(' ',st);
 com:=st[1];
 delete(st,1,p);
 val(st,l,code);
 case com of
  'I':ins(l);
  'D':del(l);
  'R':rot(l);
  'G':writeln(a[gb]);
  'M':gb:=l+1;
  'P':dec(gb);
  'N':inc(gb);
 end;
end;

procedure main;
var i:longint;
begin
 ini;
 for i:=1 to n do command;
 close(input);close(output);
end;
begin
 main;
end.