UVa442

来源:互联网 发布:淘宝卖家信用贷款 编辑:程序博客网 时间:2024/05/22 01:47
#pragma warning(disable:4996)#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<vector>#include<algorithm>#include<iostream>#include<time.h>#include<set>#include<sstream>#include<functional>#include<cassert>#include<list>#include<iterator>#include<utility>#include <stdexcept>#include <sstream>#include <fstream>#include<ctype.h>#include<map>#include<stack>using namespace std;int length;struct{    int x, y;}word[50000];stack<int> s;void print(string str){    int sum = 0;    int len = str.size();    if (len == 1)    {        cout << 0 << endl;        return;    }    int k = 0;    while (k < len)    {        k++;        if (str[k - 1] != ')')        {            int a;            if (str[k - 1] >= 'A'&&str[k - 1] <= 'Z')                a = str[k - 1] - 'A';            else            {                a = -1;            }            s.push(a);        }        else        {            int tmp1, tmp2;            tmp2 = s.top();            s.pop();            tmp1 = s.top();            s.pop();            s.pop();            if (word[tmp1].y != word[tmp2].x)            {                cout << "error" << endl;                return;            }            sum = sum + word[tmp1].x*word[tmp1].y*word[tmp2].y;            length++;            word[length].x = word[tmp1].x;            word[length].y = word[tmp2].y;            s.push(length);        }    }    cout << sum << endl;    return;}int main(){    int n;    cin >> n;    for (int i = 0;i < n;i++)    {        length = n - 1;        char temp;        cin >> temp;        cin >> word[temp - 'A'].x;        cin >> word[temp - 'A'].y;    }    string str;    while (cin >> str)    {        print(str);    }    return 0;}
0 0