HDU6144 Arithmetic of Bomb

2 篇文章 0 订阅
1 篇文章 0 订阅

题目链接: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.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值