比赛 HAOI2009 模拟试题2 评测结果 WWWWWWEEWW
题目名称 可可的文本编辑器 最终得分 0
用户昵称 bly1991 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-04-22 10:54:25
显示代码纯文本
program bly(input,output);
var
  f:array[0..10000] of char;
  g,i,j:longint;
  n,m0,m,long,k,code:longint;
  ch:char;
  st,st0,str:string;
  f1,f2:text;

  procedure wr;
  var
    i0:longint;
  begin
    for i0:=1 to long do write(f[i0]);
    writeln;
  end;

  procedure insert(n0:longint;st0:string);
  var
    i0,j0:longint;
  begin
    j0:=1;
    for i0:=g to g+n0-1 do begin
      f[i0+n0+1]:=f[i0+1];
      f[i0+1]:=st0[j0];
      inc(j0);
    end;
    long:=long+n0;
  end;

  procedure move(k0:longint);
  begin
    g:=k0;
  end;

  procedure delete(n0:longint);
  var
    i0:longint;
  begin
    for i0:=g+n0+1 to long do begin
      f[i0-n0]:=f[i0];
      f[i0]:=' ';
    end;
    long:=long-n0;
  end;

  procedure prev;
  begin
    g:=g-1;
  end;

  procedure next;
  begin
    g:=g+1;
  end;

  procedure get;
  begin
    writeln(f2,f[g+1]);
  end;

  procedure rotate(n0:longint);
  var
    i0,j0:longint;
    z:char;
  begin
    j0:=g+n0;
    for i0:=g+1 to g+n0 div 2 do begin
      z:=f[i0];
      f[i0]:=f[j0];
      f[j0]:=z;
      dec(j0);
    end;
  end;
begin
  long:=0;
  g:=0;
  assign(f1,'editor.in');
  reset(f1);
  readln(f1,n);
  assign(f2,'editor.out');
  rewrite(f2);
  for i:=1 to n do begin
    readln(f1,st);
    m0:=pos(' ',st);
    str:=copy(st,m0+1,length(st)-m0);
    val(str,m,code);
    case st[1] of
      'I':begin readln(f1,st0); insert(m,st0); end;
      'M':begin move(m); end;
      'D':begin delete(m); end;
      'R':begin rotate(m); end;
      'G':begin get; end;
      'P':begin prev; end;
      'N':begin next; end;
    end;
  end;
  close(f1);
  close(f2);
end.