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

实现简单计算器功能

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

#include<bits/stdc++.h>
using namespace std;
int judge(string s);
int main(){
    string s;
    cin>>s;
    int a=judge(s);
    int b=0,c=0;
    cin>>b>>c;
    if(a==1){
        cout<<b+c<<endl;
    }else if(a==2){
        cout<<b-c<<endl;
    }else if(a==3){
        cout<<b*c<<endl;
    }else if(a==4){
        if(c==0){
            cout<<"Error"<<endl;
        }else{
            cout<<b/c<<endl;
        }
    }
    return 0;
}
int judge(string s){
    for(int i=0;s[i]!='\0';i++){
        if(isupper(s[i])){
            s[i]=tolower(s[i]);
        }
    }
    if(s=="add"){
        return 1;
    }else if(s=="sub"){
        return 2;
    }else if(s=="mul"){
        return 3;
    }else if(s=="div"){
        return 4;
    }
    return 0;
}

全部评论

相关推荐

半解316:内容充实,细节需要修改一下。 1,整体压缩为一页。所有内容顶格。 2,项目描述删除,直接写个人工作量 修改完之后还需要建议,可以私聊
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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