# 1541 - Student’s question

696 次提交 134 次通过

YYis a student. He is tired of calculating the quadratic equation. He wants you to help him to get the result of the quadratic equation. The quadratic equation’ format is as follows: ax^2+bx+c=0.

The first line contains a single positive integer N, indicating the number of datasets. The next N lines are n datasets. Every line contains three integers indicating integer numbers a,b,c (a≠0).

For every dataset you should output the result in a single line. If there are two same results, you should just output once. If there are two different results, you should output them separated by a space. Be sure the later is larger than the former. Output the result to 2 decimal places. If there is no solution, output “NO”.

3
1 2 1
1 2 3
1 -9 6

-1.00
NO
0.73 8.27

1 #include <bits/stdc++.h>
2 using namespace std;
3 int main()
4 {
5     double n,a,b,c;
6     while(cin>>n)
7     {
8         while(n--)
9         {
10             cin>>a>>b>>c;
11             if(a==0)break;
12             else
13             {
14             if(b*b-4*a*c>=0)
15             {
16                 double t1=(-b)/a;
17                 double t2=c/a;
18                 double t3=sqrt(t1*t1-4*t2);
19                 double x1=(t1+t3)/2;
20                 double x2=(t1-t3)/2;
21                 if(x1==x2) cout<<fixed<<setprecision(2)<<x1<<endl;
22                 else if(x1<x2)
23                 cout<<fixed<<setprecision(2)<<x1<<" "<<x2<<endl;
24                 else if(x1>x2)
25                     cout<<fixed<<setprecision(2)<<x2<<" "<<x1<<endl;
26             }
27             else cout<<"NO"<<endl;
28             }
29         }
30     }
31     return 0;
32 }

780 篇文章62 人订阅

0 条评论

## 相关文章

3535

3356

### Python学习笔记三（常用运算符）

2017年年终确定的从2018年开始学习一门新的语言。随着机器学习人工智能的日渐深入，是时候有必要掌握以下Python了。博客今天更新第三篇学习记录，关于Pyt...

922

2259

3384

1505

6455

2483

721

2689