1.注意怎么处理输入的数据
2.利用两个栈来实现运算
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e6+7;
const int mod = 1e9+7;
char a[maxn];
stack <char> mystacka;
stack <int> mystackb;
int main()
{
int n,cnt=2;
scanf("%d", &n);
getchar();
gets(a);
int len=strlen(a);
for(int i=0; i<len; i++) {
if(a[i]==' ') continue;
if(a[i]<='9'&&a[i]>='0')
{
int sz=0;
while(a[i]<='9'&&a[i]>='0') {
sz=sz*10+(a[i]-'0');
i++;
}
i--;
mystacka.push('1');
mystackb.push(sz);
}
else {
if(a[i]=='(')
{
mystacka.push('(');
cnt++;
}
else if(a[i]==')')
{
ll tmp=0,cmp;
ll ans=0,ank=1;
while(mystacka.top()!='(') {
tmp++;
mystacka.pop();
}
mystacka.pop();
if(cnt%2==0) {
for(int j=1; j<=tmp; j++) {
cmp=mystackb.top();
mystackb.pop();
ans=(ans%mod+cmp%mod)%mod;
}
mystackb.push(ans);
cnt--;
}
else {
for(int j=1; j<=tmp; j++) {
cmp=mystackb.top();
mystackb.pop();
ank=(ank%mod*cmp%mod)%mod;
}
mystackb.push(ank);
cnt--;
}
mystacka.push('1');
}
}
}
ll miao=0;
while(!mystackb.empty()) {
miao=(miao%mod+mystackb.top()%mod)%mod;
mystackb.pop();
}
printf("%d\n",miao);
}