2 条题解
-
3
#include <iostream> #include <cstdio> #include <cmath> using namespace std; int main() { double a,b,c,x1,x2; cin >> a >> b >> c; if(a == 0 || b*b - 4*a*c < 0) cout << "No answer!"; else { x1 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a); x2 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a); /* if(x1 > x2) swap(x1,x2); */ printf("The first root is: %.2f\nThe second root is: %.2f",x1,x2); } return 0; } -
1
匪肠的煎蛋:
#include<bits/stdc++.h> using namespace std; int main(){ double a,b,c;//不double(float/...)0分! cin>>a>>b>>c; if(a==0||b*b-4*a*c<0) return 0; double maxx=(-b+sqrt(b*b-4*a*c))/2/a; double minn=(-b-sqrt(b*b-4*a*c))/2/a; /* if(maxx<minn){ int d=maxx; maxx=minn; minn=d; } */ //因为所有测试点中,a、b、c均没有负数情况,所以没有这串代码也能侥幸AC😃😃😃 printf("The first root is: %.2lf\n",maxx); //cout<<"The first root is: "<<maxx<<"\n"; printf("The second root is: %.2lf",minn); //cout<<"The second root is: "<<minn<<"\n"; return 0; }备注:\n均可改为endl
- 1
信息
- ID
- 1493
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- 递交数
- 110
- 已通过
- 31
- 上传者