9 条题解

  • 2
    @ 2024-10-3 17:48:33
    #include<bits/stdc++.h>
    using namespace std;
    int main() 
    {
     int a,b; 
     char ch; 
     cin>>a>>b>>ch; 
     switch(ch) 
     { 
     case'+': cout<<a+b;break; 
     case'-': cout<<a-b;break; 
     case'*': cout<<a*b;break; 
     case'/': if(b==0) printf("error!"); else cout<<a/b; 
     } 
     return 0; 
    }
    
    • 2
      @ 2024-1-7 13:10:44

      #include<bits/stdc++.h> using namespace std; int main() { int a,b; char ch; cin>>a>>b>>ch; switch(ch) { case'+': cout<<a+b;break; case'-': cout<<a-b;break; case'': cout<<ab;break; case'/': if(b==0) printf("error!"); else cout<<a/b; } return 0; }

      • 0
        @ 2025-4-23 13:34:02

        好难,写了大半个中午

        #include<bits/stdc++.h> using namespace std; int main() { int a,b; char f; cin>>a>>b>>f; switch(f) { case '+':cout<<a+b;break; case '-':cout<<a-b;break; case '':cout<<ab;break; case '/':if(b==0) {cout<<"error!";return 0; } cout<<a/b;break; } return 0; }

        • 0
          @ 2024-11-12 12:53:02
          using namespace std;
          int main()
          {
          	int a,b;
          	char c;
          	cin>>a>>b>>c;
          	if(c=='+')
          	cout<<a+b;
          	else if(c=='-')
          	cout<<a-b;
          	else if(c=='*')
          	cout<<a*b;
          	else if(c=='/')
          	{
          	    if(b==0)
          		cout<<"error!";
          		else
          		cout<<a/b;	
          	}
          	return 0;
          }
          
          
          • 0

            #include<bits/stdc++.h> using namespace std; int main(){ int a,b; char op; cin>>a>>b>>op; if(op=='/'){ if(b0) puts("error!"); else cout<<a/b; }else if(op'+') cout<<a+b; else if(op=='-') cout<<a-b; else if(op=='') cout<<ab; else puts("error!"); return 0; }

            • 0

              #include<bits/stdc++.h> using namespace std; int main() { int a,b; char n; cin>>a>>b>>n; switch(n){ case'+':cout<<a+b<<endl;break; case'-':cout<<a-b<<endl;break; case'':cout<<ab<<endl;break; case'/': if(b!=0){cout<<a/b<<endl;} else {cout<<"error!"<<endl;} break;

              } return 0; }

              • 0

                思路

                当且仅当 opt=opt=/ 并且 b=0b=0 时,输出 error! 。 否则输出值。用 if 可以解决

                code

                #include<bits/stdc++.h>
                using namespace std;
                int main(){
                	int a,b;
                	char op;
                	cin>>a>>b>>op;
                	if(op=='/'){
                		if(b==0) puts("error!");
                		else cout<<a/b;
                	}else if(op=='+')
                		cout<<a+b;
                	else if(op=='-')
                		cout<<a-b;
                	else if(op=='*')
                		cout<<a*b;
                	else
                	    puts("error!");
                	return 0;
                }
                
                • 0
                  @ 2023-12-31 16:30:56

                  #include<bits/stdc++.h> using namespace std; int main() { int a,b; char ch; cin>>a>>b>>ch; switch(ch) { case'+': cout<<a+b;break; case'-': cout<<a-b;break; case'': cout<<ab;break; case'/': if(b==0) printf("error!"); else cout<<a/b; } return 0; }

                  • 0

                    考虑使用switch函数进行符号枚举

                    • 1

                    信息

                    ID
                    40
                    时间
                    1000ms
                    内存
                    256MiB
                    难度
                    4
                    标签
                    递交数
                    137
                    已通过
                    64
                    上传者