4 条题解
-
1
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
(ke,khm//咳,咳m)我非dalou,但****/*整数版*/ #include<bits/stdc++.h> using namespace std; int main() { int x,y; char z; cin>>x>>y>>z; if(z=='+') { cout<<x+y; /*+*/ } if(z=='-')/*-*/ { cout<<x-y; /*输出x-y;*/ } if(z=='*')/*×*/ { cout<<x*y; /*输出xy;*/ } if(z=='/')/*÷*/ {if(y!=0) /*y不==0*/ { printf("%.2lf",x/y);/*输出“2 long float”(.后长度为2) x÷y;*/ } else cout<<"运算符有误"; /*y==0;输出运算符有误;*/ } return 0; } -
0
累逝我了#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; } -
-2
#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
- 难度
- 1
- 标签
- 递交数
- 26
- 已通过
- 30
- 上传者