5 条题解
-
2
#include <iostream> #include <iomanip> #include <cmath> int main() { int a, b, c; std::cin >> a >> b >> c; // 计算判别式 int discriminant = b * b - 4 * a * c; if (discriminant >= 0) { // 计算两个解 double x1 = ((double)(-b) - sqrt(discriminant)) / (2 * a); double x2 = ((double)(-b) + sqrt(discriminant)) / (2 * a); // 输出两个解,保留三位小数 std::cout << std::fixed << std::setprecision(3) << std::min(x1, x2) << " " << std::max(x1, x2) << std::endl; } else { // 判别式小于 0,输出 error std::cout << "error" << std::endl; } return 0; }
-
2
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c,h; cin>>a>>b>>c; h=b*b-4*a*c; if (h<0) { cout<<"error";} else{ if (h==0) {cout<<fixed<<setprecision(3)<<(-1*b*1.0/(2*a));} else{ cout<<fixed<<setprecision(3)<<((-1*b-sqrt(h))*1.0/(2*a))<<" "<<((-1*b+sqrt(h))*1.0/(2*a)); } } return 0; }
- 1
信息
- ID
- 47
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 4
- 标签
- 递交数
- 72
- 已通过
- 32
- 上传者