//stack处理公式串
#include<iostream>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
const int maxn=30;
struct nod{
long long a,b;
}p[maxn];
nod mk(int x,int y){
nod n;
n.a=x,n.b=y;
return n;
}
stack<nod> stk;
void init(){
while(!stk.empty())
stk.pop();
}
int main(){
int T;
cin>>T;
char chr;
string s;
while(T--){
cin>>chr;
cin>>p[chr-'A'].a>>p[chr-'A'].b;
}
getchar();
while(getline(cin,s)){
init();
long long ans=0;
int jud=0;
for(int i=0;i<s.size();i++){
if(isalpha(s[i]))
stk.push(p[s[i]-'A']);
if(s[i]==')'){
nod n1=stk.top();stk.pop();
nod n2=stk.top();stk.pop();
if(n1.a!=n2.b){
jud=1;
cout<<"error"<<endl;
break;
}
else{
stk.push(mk(n2.a,n1.b));
ans+=n2.a*n2.b*n1.b;
}
}
}
if(!jud)
cout<<ans<<endl;
}
return 0;
}
UVA - 442
最新推荐文章于 2022-01-02 20:07:43 发布