2 条题解

  • 0
    @ 2025-4-13 19:35:48
    #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=='/' and y!=0){
            a=x/y;
            printf("%.1lf",a);
        }
        if(p=='/' and y==0){
            cout<<"除数不能为零";
        }
        if(p!='+' and p!='-' and p!='*' and p!='/'){
            cout<<"运算符有误";
        }
        return 0;
    }
    
    • 0
      @ 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=='/'&&b!=0){
      		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<<"运算符有误";
      	else if(c=='/'&&b==0) 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=="/":
          if y!=0:
              z=x/y
              print(format(z,'.1f'))
          else:
              print("除数不能为零")
      else:
          print("运算符有误")
      
      • 1

      信息

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