外星密码

外星密码

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.

 

转载于:https://www.cnblogs.com/vacation/p/6075630.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值