3 条题解

  • 1
    @ 2024-12-22 11:03:57

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    
    int main(){
    	double a,b;
    	char c;
    	cin>>a>>b>>c;
    	if(c=='*'){
    		printf("%.1lf",a*b);
    	}
    	else if(c=='/'){
    		printf("%.1lf",a/b);
    	}
    	else if(c=='+'){
    		printf("%.1lf",a+b);
    	}
    	else if(c=='-'){
    		printf("%.1lf",a-b);
    	}else if(c!='-'&&c!='+'&&c!='*'&&c!='/')cout<<"运算符有误";
    }
    

    Python :

    # coding=utf-8
    x=float(input())
    y=float(input())
    op=input()
    if op=="+":
        z=x+y
        print(format(z,'.1f'))
    elif op=="-":
        z=x-y
        print(format(z,'.1f'))
    elif op=="*":
        z=x*y
        print(format(z,'.1f'))
    elif op=="/":
        z=x/y
        print(format(z,'.1f'))
    else:
        print("运算符有误")
    
    • 0
      @ 2025-5-25 9:12:32

      累逝我了

      #include<bits/stdc++.h>
      using namespace std;
      int main()
      {
      	double a,b;
      	char c;
      	cin>>a>>b>>c;
      	if(c=='+')
      	{
      		cout<<fixed<<setprecision(1)<<a+b;
      	}
      	if(c=='-')
      	{
      		cout<<fixed<<setprecision(1)<<a-b;
      	}
      	if(c=='*')
      	{
      		cout<<fixed<<setprecision(1)<<a*1.0*b;
      	}
      	if(c=='/')
      	{
      		cout<<fixed<<setprecision(1)<<a*1.0/b;
      	}
      	return 0;
      } 
      
      • -1
        @ 2025-4-13 19:29:43
        #include<bits/stdc++.h>
        using namespace std;
        int main(){
            double x,y;
            double a;
            char p;
            cin>>x>>y>>p;
            if(p=='+'){
                a=x+y;
                printf("%.1lf",a);
            }
            if(p=='-'){
                a=x-y;
                printf("%.1lf",a);
            }
            if(p=='*'){
                a=x*y;
                printf("%.1lf",a);
            }
            if(p=='/'){
                a=x/y;
                printf("%.1lf",a);
            }
            if(p!='+' and p!='-' and p!='*' and p!='/'){
                cout<<"运算符有误";
            }
            return 0;
        }
        
        • 1

        信息

        ID
        120
        时间
        1000ms
        内存
        128MiB
        难度
        10
        标签
        (无)
        递交数
        8
        已通过
        5
        上传者