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

实现简单计算器功能

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;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 17:46
暑期就挂了,秋招还有机会吗
大聪明777:研发提前批,14号刚开的,官网上面的配图上有写。提前批没过的话,秋招还可以投,不过前面的笔试/面试记录会被保留,供秋招参考
26届校招投递进展
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-09 12:23
转人工😡
门口唉提是地铁杀:五次握手了
点赞 评论 收藏
分享
Yki_:你要算时间成本呀,研究生两三年,博士三四年,加起来就五六年了,如果你本科去腾讯干五年,多领五年的年薪,加上公司内涨薪,可能到时候十五年总薪资也跟博士差不多
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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