题解 | #实现简单计算器功能#

实现简单计算器功能

https://www.nowcoder.com/practice/e7c08272a4b7497fb990ce7abb1ee952

#include <iostream>
using namespace std;

int main() {

    //char str[100] = { 0 };
    //cin.getline(str, sizeof(str));

    // write your code here......
    string op;
    int x;
    int y;
    cin >> op >> x >> y;

    if (op == "add")
    {
        cout << x + y;
    }
    else if (op == "sub")
    {
        cout << x - y;
    }
    else if (op == "mul")
    {
        cout << x * y;
    }
    else if (op == "div")
    {
        if (y == 0)
        {
            cout << "Error";
        }
        else 
        {
            cout << x / y;
        }
    }

    return 0;
}

全部评论

相关推荐

刷牛客的我很豁达:你是不是对算法有什么误解,你没手握两篇顶刊顶会,还想搞算法岗,有顶刊顶会在算法岗算才入门
点赞 评论 收藏
分享
落媛媛:同学,瞅瞅我司,医疗独角兽,校招刚开,名额有限,先到先得,我的主页最新动态,绿灯直达,免笔试~
你投了多少家公司?进展是...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务