hdu(1082)

来源:互联网 发布:fc2免费视频域名 编辑:程序博客网 时间:2024/05/17 07:41
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1082

#include<stdio.h>#include<iostream>#include<map>#include<stack>#include<string>using namespace std;struct Node{    int r,c;};map<<spanstyle="color: #8e2160">char,Node>matrix;int main(){    int n;    char m;    while (~scanf("%d",&n)) {       for(inti = 0;i <n;i++){          cin>>m;          cin>>matrix[m].r>>matrix[m].c;       }       stringstr;       int i;       while(cin>>str){          int count = 0;          stack<<spanstyle="color: #4b8186">Node>s;          for(i = 0;i < str.size();i++){              if(str[i] == '(') continue;              else if(str[i] == ')'){                 Node b =s.top();                 s.pop();                 Node a =s.top();                 s.pop();                 if(b.r!= a.c){                    cout<< "error" <<endl;                    break;                 }                 count += b.c*b.r*a.r;                 Node temp ={a.r,b.c};                 s.push(temp);              }              else                 s.push(matrix[str[i]]);           }          if(i == str.size())              cout << count<< endl;       }    }    return 0;}


0 0