2 条题解

  • 0
    @ 2023-10-22 11:33:21
    #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
      @ 2023-10-2 15:52:11
      #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
      上传者