CE?
查看原帖
CE?
330451
帅皮的瓜粉楼主2020/5/13 21:42
#include<bits/stdc++.h>
using namespace std;
struct M
{
	int a,b;
	M(const int&a=0,const int&b=0):a(a),b(b){}
}a[100];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		char tmp;
		int x,y;
		cin>>tmp>>x>>y;
		a[tmp-'A']=M(x,y);
	}
	string str;
	while(cin>>str)
	{
		stack<M>s;
		bool flag=false;
		int ans=0;
		for(int i=0,len=str.size();i<len;i++)
		{
			if (str[i]>='A'&&str[i]<= 'Z')
			{
				s.push(a[str[i]-'A']);
			}
			else if(str[i]==')')
			{
				M b(s.top()); s.pop();
				M a(s.top()); s.pop();
				if (a.b!=b.a){flag=true;break;}
				s=s+a.a*a.b*b.b;
				s.push(M(a.a, b.b));
			}
		}
		
		if(flag)
		{
			puts("error"); 
		}
		else
		{
			cout<<s<<endl;
		}
		
	}
    return 0;
}

https://www.luogu.com.cn/record/33580694

2020/5/13 21:42
加载中...