比赛 HAOI2009 模拟试题2 评测结果 AAAAWAWEEE
题目名称 可可的文本编辑器 最终得分 50
用户昵称 .Xmz 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-04-22 09:54:30
显示代码纯文本
program xmz;
var
 s:array[0..210000]of char;
 h:longint;
 dd,n,a:longint;
 f1,f2:text;
 ch:char;
 qwe:boolean;
 procedure move;
  var ii:longint;
  tch:char;
  begin
   for ii:=1 to 3 do
    read(f1,tch);
   readln(f1,dd);
  end;

 procedure insert;
  var ii,aa:longint;
  tch:char;
  begin
   for ii:=1 to 5 do
    read(f1,tch);
    readln(f1,aa);h:=h+aa;
   for ii:=h downto dd+1+aa do
    s[ii]:=s[ii-aa];
   for ii:=1+dd to aa+dd do
    if ii<>aa+dd then read(f1,s[ii]) else readln(f1,s[ii]);
  end;

   procedure delete;
  var ii,aa:longint;
  tch:char;
  begin
   for ii:=1 to 5 do
    read(f1,tch);
    readln(f1,aa);h:=h-aa;
    for ii:=dd+1 to h do
     s[ii]:=s[ii+aa];
  end;

   procedure rotate;
  var ii,aa,qq,hh:longint;
  tch,t:char;
  begin
   for ii:=1 to 5 do
    read(f1,tch);
    readln(f1,aa);qq:=dd+1;hh:=dd+aa;
    while qq<hh do
     begin
      t:=s[qq];s[qq]:=s[hh];s[hh]:=t;
      qq:=qq+1;hh:=hh-1;
     end;
  end;

   procedure get;
  var
  tch:char;
  begin
    readln(f1,tch);
    if qwe=true then writeln(f2);
    qwe:=true;
    write(f2,s[dd+1]);
  end;

  procedure prev;
  var
  tch:char;
  begin
    readln(f1,tch);
    dd:=dd-1;
  end;

  procedure next;
  var
  tch:char;
  begin
    readln(f1,tch);
    dd:=dd+1;
  end;


begin
 assign(f1,'editor.in');assign(f2,'editor.out');
 reset(f1);rewrite(f2);
 readln(f1,n);
 for a:=1 to n do
  begin
   read(f1,ch);
   if ch='I' then insert;
   if ch='M' then move;
   if ch='D' then delete;
   if ch='R' then rotate;
   if ch='G' then get;
   if ch='P' then prev;
   if ch='N' then next;
  end;
 close(f1);close(f2);
end.