百(开)度(黑)之星复赛

1001

Arithmetic of Bomb

题意:中文题

思路:模拟

AC代码:

#include "iostream"
#include "iomanip"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#pragma comment(linker, "/STACK:102400000,102400000")
#define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
#define mem(a,x) memset(a,x,sizeof(a))
#define step(x) fixed<< setprecision(x)<<
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ll long long
#define endl ("\n")
#define ft first
#define sd second
#define lrt (rt<<1)
#define rrt (rt<<1|1)
using namespace std;
const ll mod=1e9+7;
const ll INF = 1e18+1LL;
const int inf = 1e9+1e8;
const double PI=acos(-1.0);
const int N=1e5+100;

string anss1,tmp,s;
char ss[N];
ll MOD(char *s){
    ll len = strlen(s);
    ll anss1 = 0;
    for(ll i = 0; i < len; i++)
        anss1 = (((ll) anss1*10 + s[i] - '0') % mod);
    return anss1;
}

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T; cin>>T;
    while(T--){
        cin>>s; int ls=s.size();
        anss1="",tmp=""; int flag=0,bit=1,t=0,ff=0;
        for(int i=0; i<ls; ++i){
            if(flag==0 && s[i]>='0' && s[i]<='9'){
                tmp+=s[i]; //cout<<s[i]<<endl;
            }
            if(s[i]=='#'){
                flag=1; ff=1;
            }
            if(flag==1 && s[i]>='0' && s[i]<='9'){
                t+=(s[i]-'0')*bit;
                bit*=10;     //cout<<t<<"QQQ\n";
            }
            if(flag==1 && s[i]==')'){ //cout<<tmp<<endl;
                for(int j=1; j<=t; ++j){
                    anss1+=tmp;
                }
                flag=0, bit=1, t=0, tmp="";
            }
            if(flag==0 && s[i]=='('){
                anss1+=tmp;
                tmp="";
            }
        }
        if(tmp.size()!=0) anss1+=tmp;
        for(int i=0; i<anss1.size(); ++i){
            ss[i]=anss1[i]; ss[i+1]='\0';
        }
        ll anss1s=MOD(ss);
        cout<<anss1s<<endl;
    }
    return 0;
}

 

posted on 2017-08-18 16:38  lazzzy  阅读(146)  评论(0编辑  收藏  举报

导航