Ghy_boy @ 2023-11-01 18:43:03
#include<bits/stdc++.h>
using namespace std;
int d(int a,int b,char c,bool z){
bool xe=0;
if(c=='+'){return a+b;}
if(c=='-'){return a-b;}
if(c=='*'){return a*b;}
if(c='/'){
if(b==0) {z=1;return z;}
if(b>0) return a/b;
}
}
int main(){
int a,b;
char c;
bool z=0;
cin>>a>>b>>c;
if(c != '+' && c != '-' && c != '*' && c != '/'){
cout<<"Invalid operator!";
return 0;
}
if(d(a,b,c,z)==1){
cout<<"Divided by zero!";
return 0;
}
else{
cout<<d(a,b,c,z);
}
return 0;
}
by __zhy__ @ 2023-11-01 19:24:02
@1111111x
#include<bits/stdc++.h>
using namespace std;
int d(int a,int b,char c){
if(c=='+'){return a+b;}
if(c=='-'){return a-b;}
if(c=='*'){return a*b;}
if(c=='/'){
if(b==0) return -2e9;
if(b>0) return a/b;
}
}
int main(){
int a,b;
char c;
bool z=0;
cin>>a>>b>>c;
if(c != '+' && c != '-' && c != '*' && c != '/'){
cout<<"Invalid operator!";
return 0;
}
if(d(a,b,c)==-2e9){
cout<<"Divided by zero!";
return 0;
}
else{
cout<<d(a,b,c);
}
return 0;
}
by Ghy_boy @ 2023-11-01 21:32:53
@zhenghaoyi 谢谢大佬