文章

55

粉丝

317

获赞

160

访问

32.9k

头像
简单计算器 题解:数据结构里面学的中序转后序+后序求值(两个栈实现)
P1322 浙江大学机试题
发布于2025年3月4日 12:19
阅读数 196

#include<iostream>
#include<stack>
#include<string>
#include<map>
#include<cstdio>
using namespace std;
//执行简单运算
float doCal(float a, float b, char c) 
{
    if (c == '+') return a + b;
    if (c == '-') return  b - a;
    if (c == '/') return  b / a;
    if (c == '*') return  a * b;
    return -1;

}
//执行结果栈的运算
void doCalWithStack(stack<float> &st, char c)
{
    float t = st.top();
    st.pop();
    float t2 = st.top();
    float t3 = doCal(t, t2, c);
    st.pop();
    st.push(t3);

}

int main() 
{
    string str;
    while (getline(cin, str)) 
    {
        if (str == "0") break;
    &n...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发