zoukankan      html  css  js  c++  java
  • L2-033 简单计算器 (25 分)

    水题~。

    const int N=1010;
    int a[N];
    stack<int> num;
    stack<char> opt;
    int n;
    
    int main()
    {
        cin>>n;
    
        for(int i=0;i<n;i++)
        {
            int x;
            cin>>x;
            num.push(x);
        }
    
        for(int i=0;i<n-1;i++)
        {
            char op;
            cin>>op;
            opt.push(op);
        }
    
        for(int i=0;i<n-1;i++)
        {
            int a=num.top();
            num.pop();
            int b=num.top();
            num.pop();
            char op=opt.top();
            opt.pop();
    
            if(op == '+')
                num.push(a+b);
            else if(op == '-')
                num.push(b-a);
            else if(op == '*')
                num.push(a*b);
            else
            {
                if(a == 0)
                {
                    printf("ERROR: %d/0
    ",b);
                    return 0;
                }
                num.push(b/a);
            }
        }
        cout<<num.top()<<endl;
    
        //system("pause");
        return 0;
    }
    
  • 相关阅读:
    文件路径与操作系统
    试验10
    shiyan9
    sql
    shiyan8
    iostream
    shiyan7
    CDMA
    试验6
    试验5
  • 原文地址:https://www.cnblogs.com/fxh0707/p/14683125.html
Copyright © 2011-2022 走看看