博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Basic Calculator II
阅读量:2341 次
发布时间:2019-05-10

本文共 1424 字,大约阅读时间需要 4 分钟。

这个题刚刚做过。是一个c++的实验课,所以我直接用别人的代码了
当然,博客上的代码是我自己的。

#include
#include
#include
using namespace std;char priority[7][7]={ {
'<','<','<','<','>','>','>'}, {
'<','<','<','<','>','>','>'}, {
'>','>','<','<','>','>','>'}, {
'>','>','<','<','>','>','>'}, {
'>','>','>','>','>','=','>'}, {
'<','<','<','<','=','0','>'}, {
'<','<','<','<','>','<','='}};int detect(char temp){ char oper[7]={
'+','-','*','/','(',')','#'}; for(int i=0;i<7;i++) { if(temp==oper[i]) { return i; } } return 0;}char comp(char op1,char op2){ int row=detect(op1); int col=detect(op2); return priority[row][col];}int caclu(int n1,int n2,char op){ switch( op) { case '+': return n1+n2; break; case '-': return n1-n2; break; case '*': return n1*n2; break; case '/': if(n2==0) { cout<<"error // n2 is zero"<
intStack; stack
opStack; string input; cin>>input; opStack.push('#'); int temp=0; int n=input.size(); for(int i=0;i
<': { int tempN1=intStack.top(); intStack.pop(); int tempN2=intStack.top(); char tempOp=opStack.top(); opStack.pop(); intStack.pop(); int tempResult=caclu(tempN2,tempN1,tempOp); intStack.push(tempResult); goto here; break; } case '>': opStack.push(input[i]); break; } } } cout<

转载地址:http://abuvb.baihongyu.com/

你可能感兴趣的文章
c++CreateEvent函数在多线程中使用及实例
查看>>
c++多线程同步(1)
查看>>
Windows 下 C/C++ 多线程编程入门参考范例
查看>>
浅析stack around the variable was corrupted
查看>>
RGB与YUV转换
查看>>
YUV转RGB的相关函数
查看>>
ES(Elasticsearch)排序与相关性
查看>>
ES(Elasticsearch)分片内部原理
查看>>
Java IO(概述)
查看>>
Java IO(文件、管道、字节和字符数组)
查看>>
Java IO(流、Reader And Writer、异常处理)
查看>>
Java IO(RandomAccessFile、File、PipedInputStream、PipedOutputStream)
查看>>
Java NIO(二) Channel
查看>>
Java NIO(三) Buffer
查看>>
Java NIO(五) Selector
查看>>
Java NIO(六)SocketChannel、ServerSocketChannel
查看>>
6 Netty 架构剖析
查看>>
Netty简介
查看>>
Redis,API的理解和使用-全局命令
查看>>
shell之eval
查看>>