崩溃,测试点2 WA ,求助
查看原帖
崩溃,测试点2 WA ,求助
906826
ZWK210917楼主2023/8/31 17:54
#include<bits/stdc++.h>
using namespace std;
stack<int> stI;
stack<char> stC;
stack<int> stCan;
int SI(string s){
	stringstream ss;
	ss<<s;
	int d;
	ss>>d;
	return d;
}
int main(){
	string s;
	getline(cin,s);
	long long len=s.size();
	int flag=0;
	long long ans=0;
	stCan.push(0);
	for(int i=0;i<len;i++){
		if(s[i]=='R'){
			i+=7;
			string a;
			while(s[i]>='0'&&s[i]<='9'){
				a+=s[i];
				i++;
			}
			stI.push(SI(a));
			flag++;
			stC.push('[');
		}
		else if(s[i]=='F'){
			if(flag!=0){
				i+=3;
				string a;
				while(s[i]>='0'&&s[i]<='9'){
					a+=s[i];
					i++;
				}
				stC.push('F');
				stCan.push(SI(a));
			}
			else{
				i+=3;
				string a;
				while(s[i]>='0'&&s[i]<='9'){
					a+=s[i];
					i++;
				}
				ans+=SI(a);
			}
			if(s[i]==']')
				i--;
		}
		else if(s[i]=='B'){
			if(flag!=0){
				i+=3;
				string a;
				while(s[i]>='0'&&s[i]<='9'){
					a+=s[i];
					i++;
				}
				stC.push('B');
				stCan.push(SI(a));
			}
			else{
				i+=3;
				string a;
				while(s[i]>='0'&&s[i]<='9'){
					a+=s[i];
					i++;
				}
				ans-=SI(a);
			}
			if(s[i]==']')
				i--;
		}
		else if(s[i]==']'){
			long long t=stI.top();
			stI.pop();
			long long ansT=0;
			while(stC.top()!='['){
				if(stC.top()=='F'){
					ansT+=stCan.top()*t;
				}
				else if(stC.top()=='B'){
					ansT-=stCan.top()*t;
				}
				stC.pop();
				stCan.pop();
			}
			stC.pop();
			stC.push('F');
			stCan.push(ansT);
		}
	}
	cout<<abs(ans+stCan.top());
	return 0;
}

求助,90分,请各位dalao帮忙看看,非常感谢。

2023/8/31 17:54
加载中...