HDU6144 Arithmetic of Bomb

来源:互联网 发布:欧碧诗胶原蛋白知乎 编辑:程序博客网 时间:2024/06/16 03:12

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6144
字符串的展开+大数取模
由于不存在括号套括号的鬼畜神奇情况,所以直接模拟即可

附大数取模:

 len:=length(ss); ans:=0; for i:=1 to len do ans:=(int64(ans)*10+ord(ss[i])-48)mod tt;

贴代码

 const tt=1000000007; var s,ss,cc,bb:ansistring;     top,Q,i,t,len,bo,num,j,kk,k1,ans:longint;     a:array[0..10005]of ansistring; begin//  assign(input,'6144.in');reset(input);//  assign(output,'6144.out');rewrite(output);  readln(Q);  top:=0;  for t:=1 to Q do   begin    readln(s);bo:=0;    if s='' then begin writeln(0); continue; end;    ss:=''; kk:=0;    i:=1;len:=length(s);    while i<=len do     begin      if s[i] in ['0'..'9'] then begin                                  num:=0; k1:=0;j:=i;                                  while (j<=len)and(s[j] in['0'..'9'])do inc(j);                                  inc(top);a[top]:=copy(s,i,j-i);                                  i:=j;                                 if bo=1 then begin val(a[top],num);dec(top);for j:=1 to num do ss:=ss+a[top];dec(top);end                                         else if (i>len)or(s[i]='(')then begin ss:=ss+a[top];dec(top);end;                                 bo:=0;                                 end else      if s[i]='#' then begin inc(i);bo:=1;end else inc(i);     end;    fillchar(a,sizeof(a),0);    len:=length(ss);    ans:=0;    for i:=1 to len do ans:=(int64(ans)*10+ord(ss[i])-48)mod tt;    writeln(ans);   end;//  close(input);close(output); end.

【写的有漏洞的,欢迎路过大神吐槽】
2017/08/24 18:29:27
Ending.