比赛 HAOI2009 模拟试题2 评测结果 AAAAEAATTT
题目名称 可可的文本编辑器 最终得分 60
用户昵称 lc 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-04-22 11:18:03
显示代码纯文本
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.