90分求助(玄关)
查看原帖
90分求助(玄关)
1253423
Go_Forward楼主2024/6/21 19:26
#include<bits/stdc++.h>
using namespace std;
string s;
long long does(string x)
{
	long long ans=0;
	int id=0;
	while(id<x.size())
	{
		if(x[id]=='F')
		{
			id+=3;
			long long ls=0;
			while(isdigit(x[id]))
			  ls=ls*10+x[id]-'0',++id;
			ans+=ls;
		}
		if(x[id]=='B')
		{
			id+=3;
			long long ls=0;
			while(isdigit(x[id]))
			  ls=ls*10+x[id]-'0',++id;
			ans-=ls;
		}
		++id;
	}
	//cout<<ans<<'\n';
	return ans;
}
long long get(string x)
{
	if(x[0]=='[')
	  x.erase(0,1);
	//cout<<x<<'\n';
	long long xb=x.find('[');
	if(xb==string::npos)
	{
		//cout<<"over : ";
		return does(x);
	}
	long long ans=0;
	if(x[0]!='R')
	{
		//cout<<"++=";
		ans+=does(x.substr(0,x.find('R')));
	}
	if(x[x.size()-1]!=']')
	  ans+=get(x.substr(x.find_last_of(']')+1)); 
	long long c=xb-1;
	string ls;
	while(isdigit(x[c]))
	  ls=x[c]+ls,--c;
	stringstream ss;
	  ss<<ls;
	  ss>>c;
	long long y=0;
	while(x[xb+y]!=']')
	  ++y;
	//cout<<"c="<<c<<'\n';
	return ans+c*get(x.substr(xb,y+1));
}
int main()
{
	getline(cin,s);
	cout<<abs(get(s));
}

90分求助,WA#2,求hack

2024/6/21 19:26
加载中...