uva 442
来源:互联网 发布:lumia刷linux 编辑:程序博客网 时间:2024/05/16 19:02
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stack>using namespace std;const int maxn = 100 + 50;struct Matrix{int rows;int cols;};Matrix mat[26];int n, rows, cols;char ch;char str[maxn];stack<Matrix> matStack;long long int res = 0, temp = 0;bool flag = true;int main(){freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);scanf("%d", &n);getchar();for (int i = 0; i < n; i++){scanf("%c %d %d", &ch, &rows, &cols);mat[ch - 'A'].cols = cols;mat[ch - 'A'].rows = rows;getchar();}while (EOF != scanf("%s", str)){res = 0;flag = true;int length = strlen(str);while (!matStack.empty())matStack.pop();for (int i = 0; i < length; i++){if ('(' == str[i])continue;if (')' != str[i])matStack.push(mat[str[i] - 'A']);else{Matrix a = matStack.top();matStack.pop();Matrix b = matStack.top();matStack.pop();if (b.cols != a.rows){flag = false;break;}res += b.rows * b.cols * a.cols;Matrix nm;nm.rows = b.rows;nm.cols = a.cols;matStack.push(nm);}}if (!flag)printf("error\n");elseprintf("%d\n", res);}//while scanfreturn 0;}
0 0
- uva 442
- UVA 442
- uva 442
- uva 442
- uva 442
- uva 442
- UVA - 442
- UVA 442
- UVA 442
- UVA 442
- uva oj 442
- uva 442(线性表)
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- 华为公司的代码风格
- 洛谷 P1155 [NOIP2008 T4] 双栈排序
- cocos2dx 3.x 相机机制
- 给VMware下的Linux扩展磁盘空间(以CentOS6为例)
- 做科研的几点体会:如何多发 SCI
- uva 442
- kafka low levle实例
- leetCode_Number of Digit One
- 引用zepto jquery图片懒加载 浏览器如何测试
- FragmentPagerAdapter 滑动过后界面不显示的解决方案
- 这样读源码,不牛X也难
- jstl标签for循环和if判断的使用
- SYN flood及其应对方法
- mysql中文显示为问号?的解决方法