#include<iostream>
#include<stack>
#include<string>
#include<cctype>
using namespace std;

#define N 30
struct node
{
char m;
int r,c;
} a[N];
string s;

bool process(int& ans)
{
int len,i;
stack<node> sta;
node x,y,t;

len=s.length();
if(len==1)
{
ans=0;
return true;
}
ans=0;
for(i=0;i<len;i++)
if(isupper(s[i]))
sta.push(a[s[i]-'A']);
else if(s[i]==')')
{
x=sta.top();
sta.pop();
y=sta.top();
sta.pop();
if(x.r!=y.c) return false;
t.r=y.r;
t.c=x.c;
ans+=y.r*y.c*x.c;
sta.push(t);
}
return true;
}

int main()
{
int n,i,ans;
char c;

cin>>n;
for(i=0;i<n;i++)
{
getchar();
cin>>c;
a[c-'A'].m=c;
cin>>a[c-'A'].r>>a[c-'A'].c;
}
while(cin>>s)
{
if(!process(ans))
cout<<"error"<<endl;
else
cout<<ans<<endl;
}
return 0;
}

hdu1082的更多相关文章

  1. Matrix Chain Multiplication[HDU1082]

    Matrix Chain Multiplication Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  2. hdu-1082 Matrix Chain Multiplication---栈的运用

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1082 题目大意: 题意大致是N个矩阵,如果要求计算的矩阵例如(AB),如果A的列等于B的行,进行:A ...

随机推荐

  1. java-从这里开始认识

    <java是什么:>Programming language 程序语言Development environment 开发环境Application environment 应用环境Dep ...

  2. 剑指offer——二叉树的深度与平衡二叉树的判断

    通过后续遍历,可以减少重复访问 #include <iostream> #include <string> using namespace std; struct Binary ...

  3. Python 注释和中文乱码

    Python 注释分为三种: 1.单行注释:# 2.多行注释:前后3个单引号,或者三个双引号: 如:''' 多行注释 ''', """或者 多行注释 '"&qu ...

  4. POJ Layout

    A - Layout Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit S ...

  5. M1905

    11.09    11:00------102万 11.09     14:00---103万 11.12    16:00------103万 11.19     16:00---94万 11.20 ...

  6. Base64Util工具类

    package com.qianmi.weidian.common.util; import java.io.*; /** * This class provides encode/decode fo ...

  7. Qt中 QTableWidget用法总结

    转自--> http://edsionte.com/techblog/archives/3014 http://hi.baidu.com/fightiger/item/693aaa0f0f87d ...

  8. BZOJ2034 [2009国家集训队]最大收益

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  9. Linux配置redis服务器

    1.安装redis 2.开启6379端口,使外部机器能够访问 3.

  10. vim乱码的解决

    解决vim文件乱码,打开文件乱码,菜单,提示信息乱码: 有四个跟字符编码方式有关的选项,encoding.fileencoding.fileencodings.termencoding 在linux中 ...