前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布

hdu1082

作者头像
@坤的
发布2018-06-04 11:21:06
3780
发布2018-06-04 11:21:06
举报
文章被收录于专栏:*坤的Blog

#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; }

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017-01-22 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档