4 条题解
-
1房佳坤 LV 8 @ 2021-02-15 20:33:48
#include<bits/stdc++.h> using namespace std;//这题用switch不比if好吗(光速逃 int a,b; char c; int main() { cin>>a>>b>>c; switch(c){ case '+' :cout<<a+b;break; case '-' :cout<<a-b;break; case '*' :cout<<a*b;break; case '/' :cout<<a/b;break; } return 0; }
-
12020-07-24 15:53:02@
一个一个判断吧
#include<bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; char c; cin >> c; if(c == '+') { cout << a + b; } else if(c == '-') { if(a <= b) { cout << b - a; } else { cout << a - b; } } else if(c == '*') { cout << a * b; } else { if(a <= b) { cout << b / a; } else { cout << a / b; } } cout << endl; return 0; }
-
12020-05-27 22:19:17@
没什么好讲的,水题一道。四个
if
语句分别判断,然后就\(ok\)了。
代码:#include<bits/stdc++.h> using namespace std; int main(){ long long a, b; cin >> a >> b; char c; cin >> c; if (c=='+') cout << a+b << endl; if (c=='-') cout << a-b << endl; if (c=='*') cout << a*b << endl; if (c=='/') cout << a/b << endl; return 0; }
-
02020-07-31 15:33:25@
#include <iostream> #include <cstdio> using namespace std; int main() { int a, b; char op; cin >> a >> b >> op; switch (op) { 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