求助!!SOS!!细节错误??
查看原帖
求助!!SOS!!细节错误??
225616
Pansq楼主2020/5/9 22:09
#include <bits/stdc++.h>
#define N 100001
#define mod 10007
using namespace std;
char Stack[N],str[N];
int ans[N][2];
int top_stack=0,top_ans=0;
void work(int f,int t,int f1,int t1,char now) {
	switch(now) {
		case '+': {
			f=(f*f1)%mod;
        	t=(f*t1)%mod+(t*f1)%mod+(t*t1)%mod;
			break;
		}
		case '*': {
			f=(f*t1)%mod+(t*f1)%mod+(f1*f)%mod;
        	t=(t*t1)%mod;
			break;
		}
	}
}
int main(void) { 
	int n;
	cin>>n;
	ans[1][0]=1;
	ans[1][1]=1;
	cin>>str;
	for(int i=0;i<strlen(str);i++) {
		switch(str[i]) {
			case '(': {
				Stack[++top_stack]='(';
				break;
			}
			case ')': {
				char ch=')';
				while(ch!='(') {
					work(ans[top_ans][0],ans[top_ans][1],ans[top_ans-1][0],ans[top_ans-1][1],'(');
					top_stack--;
					top_ans--;
					ch=Stack[top_stack];
				}
				top_stack--;
				break;
			}
			default: {
				char ch=str[i];
				while(ch>Stack[top_stack] && Stack[top_stack]!='(') {
					work(ans[top_ans][0],ans[top_ans][1],ans[top_ans-1][0],ans[top_ans-1][1],'(');
					top_stack--;
					top_ans--;
					ch=Stack[top_stack];
				}
				Stack[++top_stack]=str[i];
				ans[++top_ans][0]=1;
				ans[top_ans][1]=1;
				break;
			}
		}
	}
	cout<<ans[top_ans][0];
	return 0;
}
2020/5/9 22:09
加载中...