zoukankan      html  css  js  c++  java
  • 2020年团体程序设计天梯赛 L2-1 简单计算器

    思路:

    水题,略过

    Tip:

    #include <bits/stdc++.h>
    
    using namespace std;
    typedef long long ll;
    
    stack<int> s1;
    stack<char> s2;
    
    int main() {
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++) {
            int tmp;
            cin >> tmp;
            s1.push(tmp);
        }
        for (int i = 1; i <= n - 1; i++) {
            char tmp;
            cin >> tmp;
            s2.push(tmp);
        }
        while (!s2.empty()) {
            int n1 = s1.top();
            s1.pop();
            int n2 = s1.top();
            s1.pop();
            char s = s2.top();
            s2.pop();
            int n3;
            if (s == '+') {
                n3 = n2 + n1;
            } else if (s == '-') {
                n3 = n2 - n1;
            } else if (s == '*') {
                n3 = n2 * n1;
            } else if (s == '/') {
                if (n1 == 0) {
                    cout << "ERROR: " << n2 << "/" << n1 << endl;
                    return 0;
                }
                n3 = n2 / n1;
            }
            s1.push(n3);
        }
        cout << s1.top() << endl;
        return 0;
    }
    

      

  • 相关阅读:
    侧边工具栏
    proguard 使用说明
    人员组成
    google play
    大数据平台相关
    HttpClient
    库克
    html5 开发 android 注意点
    htm5 动画制作 工具
    JAVA取得WEBROOT物理路径
  • 原文地址:https://www.cnblogs.com/Whiteying/p/14056493.html
Copyright © 2011-2022 走看看