| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY 
共有 257 人关注过本帖
标题:[求助]谁帮我看看 那里错了
收藏  订阅  推荐  打印 
coldmoon
Rank: 1
等级:新手上路
帖子:2
积分:120
注册:2005-5-26
[求助]谁帮我看看 那里错了

#include"iostream" #include"string" #include"stack" using namespace std;

void main() { string str; //printf("Shu RU Ji Suan Si Zi!!\n(Start With '#' And End With '#')\n"); //for(int j=0;str[j]!='#';j++) //gets(&str); str="#12+6*(2+3)/3-7#"; //str[0]='#';str[1]=12;str[2]='+';str[3]=6;str[4]='*';str[5]='(';str[6]=')';str[7]=2;str[8]='+';str[9]=3;str[10]=')';str[11]='/';str[12]=3;str[13]='-';str[14]=7;str[15]='#'; stack<char> s1; stack<int> s2; int i=1,x,fa,fb; if(str[0]=='#' ) s1.push(str[0]); else cout<<"error"; while(str[i]!='#') { if(str[i]!='+'&&str[i]!='-'&&str[i]!='*'&&str[i]!='/' &&str[i]!='('&&str[i]!=')') s2.push(str[i]); //else if(str[i]=='\0')goto lab; else if(str[i]=='+'||str[i]=='-') s1.push(str[i]); else if(str[i]=='*'||str[i]=='/') { if(s1.top()=='*'||'/') { fa=s2.top(); s2.pop(); fb=s2.top(); s2.pop(); if(str[i]=='*') x=fb*fa; else x=fb/fa; s2.push(x); s1.pop(); } else if(s1.top()=='(') { fa=s2.top(); s2.pop(); fb=s2.top(); s2.pop(); if(str[i]=='*') x=fb*fa; else x=fb/fa; s2.push(x); s1.pop(); } else s1.push(str[i]); } else if(str[i]=='(') s1.push(str[i]); else while(str[i]==')') { if(s1.top()==')') { s1.pop(); s1.pop(); } else { fa=s2.top(); s2.pop(); fb=s2.top(); s2.pop(); if(s1.top()=='+') x=fb+fa; else if(s1.top()=='-') x=fb-fa; else if(s1.top()=='*') x=fb*fa; else if(s1.top()=='/') x=fb/fa; s2.push(x); } i++; } if(s1.top()=='#') { s1.pop(); s1.pop(); cout<<"Da An Shi:"<<'%f'<<s2.top()<<'\n'; } else { fa=s2.top(); s2.pop(); fb=s2.top(); s2.pop(); if(s1.top()=='+') x=fb+fa; else if(s1.top()=='-') x=fb-fa; else if(s1.top()=='*') x=fb*fa; else if(s1.top()=='/') x=fb/fa; cout<<"Da An Shi:"<<'%f'<<x<<endl; }

} }

2005-5-26 16:24
coldmoon
Rank: 1
等级:新手上路
帖子:2
积分:120
注册:2005-5-26

这是一个运算器的实现程序 使用了栈

但出现了错误
2005-5-26 16:26
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.067570 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved