2017百度之星复赛1001Arithmetic of Bomb------hdu6144

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6144

分析:这道题挺水的,就是讲(a)#(b)表示有b个相连的a,当然也有可能有穿插不是这样表示直接给数字的,比如题目的(12)#(2)4(2)#(3)表示12124222,照着模拟就行了,注意下要到处取模,要不可能出现溢出啥的

代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod = 1000000007;
LL num10[1005];
int main() {
    int T;
    num10[0] = 1;
    for(int i= 1; i <= 1005; i++) {
        num10[i] = (num10[i-1] * 10) % mod;
    }
    scanf("%d",&T);
    while(T--) {
        string str;
        cin>>str;
        LL sum = 0;
        for(int i = 0; i < str.length(); i++) {
            if(str[i] <= '9' && str[i] >= '0')
                sum = (sum * 10 + str[i] - '0') % mod;
            else {
                i++;
                LL tmp = 0;
                LL number = 0;
                while(i < str.length() && str[i] != ')') {
                    tmp = (tmp * 10 + (str[i++] - '0')) % mod;
                    number++;
                }//cout<<str[i]<<str[i+1]<<str[i+2];
                i = i + 3;
                LL cont = 0;
                while(i < str.length() && str[i] != ')') {
                    cont = (cont * 10 + (str[i++] - '0')) % mod;
                }
                for(int j = 0; j < cont; j++) {
                    sum = (sum * num10[number] % mod + tmp + mod) % mod;
                }
            }
        }
        printf("%I64d\n",sum);
    }
    return 0;
}

 

posted @ 2017-08-18 23:29  maplefighting  阅读(185)  评论(0编辑  收藏  举报