http://acm.hdu.edu.cn/showproblem.php?pid=1082

这题开始想复杂了,error并不包括表达式本身不合法的情况

我的方法是遇到右括号就开始处理栈,如果开始最外层没有括号,就人为加上

数据应该是比较弱的,一通乱搞

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack> using namespace std ;
int n ; struct Mat
{
int op ;
int r,c ;
}M[] ;
Mat cc[] ;
char s[],ss[] ;
int main()
{
scanf("%d",&n) ;
for(int i= ;i<n ;i++)
{
char op[] ;
scanf("%s%d%d",op,&M[i].r,&M[i].c) ;
M[i].op=op[] ;
}
int tt=n ;
while(~scanf("%s",s))
{
n=tt ;
int len=strlen(s) ;
if(s[]!='(')
{
for(int i= ;i<=len ;i++)
ss[i]=s[i-] ;
ss[]='(' ;ss[len+]=')' ;
len+= ;
for(int i= ;i<len ;i++)
s[i]=ss[i] ;
}
int flag= ;
for(int i= ;i<len ;i++)
{
if(s[i]=='(' || s[i]==')')
{
flag= ;
break ;
}
}
int ans= ;
int ct= ;
stack <int> st ;
flag= ;
for(int i= ;i<len ;i++)
{
if(s[i]!=')')
{
st.push(s[i]) ;
}
else
{
int cnt= ;
while()
{
if(st.empty())break ;
if(st.top()=='(')
{
st.pop() ;
break ;
}
int temp=st.top() ;
st.pop() ;
for(int j= ;j<n ;j++)
{
if(M[j].op==temp)
{
cc[cnt++]=M[j] ;
break ;
}
}
}
for(int j=cnt- ;j>= ;j--)
{
if(cc[j+].c==cc[j].r)
{
ans+=(cc[j+].r*cc[j+].c*cc[j].c) ;
}
else
{
flag= ;
break ;
}
cc[j].r=cc[j+].r ;
}
if(!flag)break ;
cc[].op=ct++ ;
M[n++]=cc[] ;
st.push(cc[].op) ;
}
if(!flag)break ;
}
if(flag)printf("%d\n",ans) ;
else puts("error") ;
}
return ;
}

HDU 1082的更多相关文章

  1. hdu 1082, stack emulation, and how to remove redundancy 分类: hdoj 2015-07-16 02:24 86人阅读 评论(0) 收藏

    use fgets, and remove the potential '\n' in the string's last postion. (main point) remove redundanc ...

  2. Uva442 hdu 1082 Matrix Chain Multiplication

    要注意取出来的时候 先取出q的是后面那个矩阵 后取出p的是前面的矩阵 所以是判断 p.a == q.b #include <iostream> #include <stack> ...

  3. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  4. [转] HDU 题目分类

    转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...

  5. HDU ACM 题目分类

    模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...

  6. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  7. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  8. hdu 分类

    HDU分类 http://www.cnblogs.com/ACMan/archive/2012/05/26/2519550.html#2667329 努力A完.方便自己系统A题 不断更新中...... ...

  9. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

随机推荐

  1. android - anim translate中 fromXDelta、toXDelta、fromYDelta、toXDelta属性

    <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http:// ...

  2. OLAP 模型

    OLAP分析的基础是多维数据集,按照其数据存储格式的不同可以分为关系型OLAP(Relational OLAP,ROLAP)和多维型OLAP(Multidimensional OLAP,MOLAP). ...

  3. formvalidator4.1.3 使用过程中一些问题的解决

    在使用formvalidator4.1.3 插件时  发现 正常情况调用时没有问题的,但是我们的项目中需要把css  .js 之类的静态资源用单独的域名加载. 那么问题就来了在 该插件中 有一段这样的 ...

  4. CentOS 下的MySQL配置

    先贴出代码(/etc/my.cnf)如下: #The following options will be passed to all MySQL clients [client] #password ...

  5. 测试JdbcTemplate执行SQL语句和存储过程

    我在项目中需要使用到oracle的语句片段和存储过程.下面就是我的测试案例: public class DbTest extends BaseTestCase { @Resource JdbcUtil ...

  6. java 面向对象编程 --第十二章 JDK常用类

    1.  系统类 java.lang包   System类 sys.out;sys.exit;sys.gc; sys.currentTimeMillis();----得到从1970-01-01到当前时间 ...

  7. Iterator之ListIterator简介

    ListIterator是什么? (参考自百度百科) java中的ListIterator在Iterator基础上提供了add.set.previous等对列表的操作.但是ListIterator跟I ...

  8. RelativeLayout练习

    <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=&q ...

  9. CF 103E Buying Sets 最大权闭合子图,匹配 难度:4

    http://codeforces.com/problemset/problem/103/E 这道题首先一看就很像是最大权闭合子图,但是我们可以认为现在有两种点,数字和集合点,我们需要消除数字点的影响 ...

  10. Zabbix页面遇到历史记录的乱码需要修改数据库

    Zabbix页面遇到历史记录的乱码需要修改数据库: 解决办法: 1.将 zabbix 数据库中的表备份: 2.手动删除 zabbix 数据库: 3.重新创建 zabbix 库时手动指定字符集为 utf ...