2 条题解
-
0
#include<bits/stdc++.h> using namespace std; int main() { int a,b;char op; cin>>a>>b>>op; if(op=='/'&&b==0){cout<<"Divided by zero!";return 0;} if(op!='/'&&op!='*'&&op!='+'&&op!='-'){cout<<"Invalid operator!";return 0;} if(op=='+')cout<<a+b; if(op=='-')cout<<a-b; if(op=='*')cout<<a*b; if(op=='/')cout<<a/b; return 0; }
-
0
#include<iostream> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; int main(){ int a,b; char c; cin >> a >> b >> c; switch (c){ case '+': cout << a+b; break; case '-': cout << a-b; break; case '*': cout << a*b; break; case '/': if (b == 0){ cout << "Divided by zero!"; }else{ cout << a/b; } break; default: cout << "Invalid operator!"; } return 0; }
- 1
信息
- ID
- 6864
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 1
- 标签
- (无)
- 递交数
- 42
- 已通过
- 25
- 上传者