#38813: 比較特殊的解答


wuj35060@gmail.com (weng)

學校 : 不指定學校
編號 : 136034
來源 : [163.13.147.21]
最後登入時間 :
2024-11-19 09:04:52
a006. 一元二次方程式 | From: [122.100.75.165] | 發表日期 : 2023-12-25 21:25

#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    int discriminant = b * b - 4 * a * c;

    if (discriminant > 0) {
        int x1 = (-b + sqrt(discriminant)) / (2 * a);
        int x2 = (-b - sqrt(discriminant)) / (2 * a);
        cout << "Two different roots x1=" << max(x1, x2) << " , x2=" << min(x1, x2) << endl;
    } else if (discriminant == 0) {
        int x = -b / (2 * a);
        cout << "Two same roots x=" << x << endl;
    } else {
        cout << "No real root" << endl;
    }

    return 0;
}

 
ZeroJudge Forum