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

实现简单计算器功能

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

#include <iostream>
#include <string>
#include <string.h>
using namespace std;

int main() {
    string str;
    int m,n;
    cin>>str>>m>>n;
    for(auto& i:str)
        i=tolower(i);
    if(str=="add")
        cout<<m+n;
    if(str=="sub")
        cout<<m-n;
    if(str=="mul")
        cout<<m*n;
    if(str=="div"){
        if(n==0)
            cout<<"Error";
        else cout<<m/n;
    }
    return 0;
}
全部评论
这个才是王道。虽然修改了输入。
点赞 回复 分享
发布于 2024-12-13 09:03 广东

相关推荐

不愿透露姓名的神秘牛友
今天 12:10
点赞 评论 收藏
分享
07-07 17:06
已编辑
深圳技术大学 golang
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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