记录编号 9904 评测结果 AAAAEAAAAA
题目名称 [AHOI 2006] 可可的文本编辑器 最终得分 90
用户昵称 Gravatar苏轼 是否通过 未通过
代码语言 Pascal 运行时间 5.849 s
提交时间 2009-04-22 15:39:44 内存使用 0.12 MiB
显示代码纯文本
program day2_2;
 var
      n,gub:        longint;
      s,edit:            ansistring;
      ch:           char;

 function getnum(s:ansistring):longint;
   var
       num,i,k:     longint;
   begin
     num :=0;
     for i :=1 to length(S) do if s[i]=' ' then k :=i;
     for i :=k+1 to length(s) do num :=num*10+ord(s[i])-48;
     exit(num);
   end;


 procedure Main;
   var
        i,j,num:      longint;
        ss:     ansistring;

   begin
     readln(n);   gub:=0;
     for i :=1 to n do begin
       readln(s); ch :=s[1];
       case ch of
         'I':  begin
                 readln(ss);
                 edit :=copy(edit,1,gub)+ss+copy(edit,gub+1,length(edit)-gub);
               end;
         'M':  begin
                 num :=getnum(s);
                 gub :=num;
               end;
         'D':  begin
                 num :=getnum(s);
                 delete(edit,gub+1,num);
               end;
         'P':  begin
                 dec(gub);
               end;
         'N':  begin
                 inc(gub);
               end;
         'G':  begin
                 writeln(edit[gub+1]);
               end;
         'R':  begin
                 num :=getnum(s); ss:=copy(edit,gub+1,num);
                 for j :=1 to num do edit[j+gub] :=ss[num-j+1];
               end;

         end;  //case;
       end;    //for;
   end;


begin
  assign(input,'editor.in'); reset(input);
  assign(output,'editor.out'); rewrite(output);
  Main;
  close(input);  close(output);
end.