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:多线程,使用同步锁(Lock)时利用Condition类实现线程间通信

    如果程序不使用synchronized关键字来保证同步,而是直接使用Lock对象来保证同步,则系统中不存在隐式的同步监视器,也就不能用wait().notify().notifyAll()方法进行线程 ...

  2. wait(), notify(),sleep详解

    在JAVA中,是没有类似于PV操作.进程互斥等相关的方法的.JAVA的进程同步是通过synchronized()来实现的,需要说明的是,JAVA的synchronized()方法类似于操作系统概念中的 ...

  3. asp.net core StaticFiles中间件修改wwwroot

    new StaticFileOptions() { FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentD ...

  4. checkbox改成radio效果,单选,取消

    $(function () {            var allBox = $(":checkbox");            allBox.click(function ( ...

  5. Oracle中any和all的区别用法

    对于any,all的用法,书中说的比较绕口,难以理解,如果通过举例就会比较清晰. any的例子: select * from t_hq_ryxx where gongz > any (selec ...

  6. bzoj 2257: [Jsoi2009]瓶子和燃料

    #include<cstdio> #include<iostream> #include<algorithm> #include<cmath> usin ...

  7. C#点击按钮用DataGridView动态增加行、删除行,增加按钮列

    原来有一行: 点击添加,在下面增加同样的一行 新增加的行有一列删除按钮,点击某行的删除按钮时,删除当前行 方法: 哈哈,我果然好聪明啊 1.文本框.文本框.添加按钮 2.一个DataGridView( ...

  8. python开发规则

    1.Python优点:简单.优雅.明确 python缺点 2.强大的模块三房库 1.代码不能加密 3.易移植 2.速度慢 4.面向对象 5.可扩展(c\java\c#....) cpython ipy ...

  9. 继承自NSObject的类不能用CGRect

    我用的是Xcode6.2. 系统默认没有pch文件. 所以没有自动导入UIKit包. 我在继承NSObject类里也不能用CGRect或者UI开头的控件,原因也是Xcode6.2以后版本 缺少UIKi ...

  10. K2任命新的亚太区高级副总裁

    K2, 一个屡获殊荣的企业应用软件公司宣布,任命陈光明(Tan Kwang Meng, KM)为亚太区高级副总裁.这次任命是对公司持续发展的肯定,同时也是对将亚太区作为全球扩张战略的关键市场的承诺. ...