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. java代码抓取网页邮箱

    实现思路:1.使用java.net.URL对象,绑定网络上某一个网页的地址2.通过java.net.URL对象的openConnection()方法获得一个HttpConnection对象3.通过Ht ...

  2. 230. Kth Smallest Element in a BST ——迭代本质:a=xx1 while some_condition: a=xx2

    Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Not ...

  3. Oracle存储过程写法

    create or replace procedure QIANFEIGL_JIAOKUANDY( cebenh varchar2, kehuh varchar2, hetongh varchar2, ...

  4. Go语言并发与并行学习笔记(二)

    转:http://blog.csdn.net/kjfcpua/article/details/18265461 Go语言的并发和并行 不知道你有没有注意到一个现象,还是这段代码,如果我跑在两个goro ...

  5. SQL逻辑读变成零

    使用缓存HINT 让逻辑读变成0. create table t as select * from dba_objects; insert into t select * from t; commit ...

  6. The Python web services developer: XML-RPC for Python

    原文地址:http://www.ibm.com/developerworks/webservices/library/ws-pyth10/index.html 摘要:概括地说,您可以将 XML-RPC ...

  7. js基础之事件

    一.event对象 document.onclick=function(ev){ oEvent=event?event:ev;//兼容性写法 alert(oEvent.clientX); alert( ...

  8. PHP安装pthreads多线程扩展教程[windows篇]

    from:http://blog.csdn.net/aoyoo111/article/details/19020161 一.判断PHP是ts还是nts版 通过phpinfo(); 查看其中的 Thre ...

  9. STM32-AFIO

    只有使用了AFIO的事件控制寄存器.AFIO的重映射功能以及外部中断(EXTI)控制寄存器才需要开启AFIO的时钟,STM32参考手册从来没说过使用IO的复用功能就一定要开启AFIO时钟,这是个误区.

  10. POJ 3225 Help with Intervals

    U:把区间[l,r]覆盖成1I:把[0,l-1][r+1,∞]覆盖成0D:把区间[l,r]覆盖成0C:把[0,l-1][r+1,∞]覆盖成0 , 且[l,r]区间0/1互换(即异或)S:[l,r]区间 ...