题解 | #实现简单计算器功能#
实现简单计算器功能
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; }