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

实现简单计算器功能

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 广东

相关推荐

07-10 13:59
门头沟学院 Java
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-09 12:23
转人工😡
门口唉提是地铁杀:五次握手了
点赞 评论 收藏
分享
07-08 13:48
门头沟学院 C++
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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