外星密码

外星密码

COGS 1239

AYYZOJ 1916

字符串 模拟 有栈的思想

不过我写完没有想到栈

经过尝试之后应该是由内向外逐层扩展(不动脑子!)

 1 var
 2   s,plus,plu:ansistring;
 3   i,sl,sr:longint;
 4 procedure get(var x,y,num:longint);
 5 var i,k:longint;
 6     nu:ansistring;
 7 begin
 8   for i:=1 to length(s) do
 9    if s[i]='[' then x:=i;
10   for i:=1 to length(s) do
11    if (s[i]=']') and (i>x) then begin y:=i; break; end;
12   nu:='';
13   i:=x+1;
14   k:=ord(s[i])-ord('0');
15   while k in [0..9] do
16    begin
17      nu:=nu+s[i];
18      inc(i);
19      k:=ord(s[i])-ord('0');
20    end;
21   val(nu,num);
22 end;
23 procedure doit(var s:ansistring);
24 var num,i,di:longint;
25 begin
26   plus:='';
27   get(sl,sr,num);
28   di:=num div 10;
29   if di<>0 then
30    plu:=copy(s,sl+3,sr-sl-3)
31   else plu:=copy(s,sl+2,sr-sl-2);
32   for i:=1 to num-1 do
33     plus:=plus+plu;
34   delete(s,sr,1);
35   if di<>0 then
36    delete(s,sl,3)
37   else delete(s,sl,2);
38   insert(plus,s,sl);
39 end;
40 begin
41 assign(input,'passworda.in');
42 reset(input);
43 assign(output,'passworda.out');
44 rewrite(output);
45   readln(s);
46   while pos('[',s)<>0 do
47     doit(s);
48   writeln(s);
49 close(input);
50 close(output);
51 end.

 

posted @ 2016-11-17 21:42  ZJQCation  阅读(511)  评论(0编辑  收藏  举报