3 条题解

  • 2
    @ 2026-7-28 17:00:24

    不喜勿喷!

    #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 root.";
    	else
    	{
    		x1 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a);
    		x2 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a);
    		if(x1 == x2)
    			printf("x=%.2f",x1);
    		else
    		{
    			if(x1 > x2)
    				swap(x1,x2);
    			printf("x1=%.2f\nx2=%.2f",x1,x2);
    		}
    	}
    	
    	return 0;
    }
    
    

    信息

    ID
    1499
    时间
    1000ms
    内存
    256MiB
    难度
    4
    标签
    递交数
    38
    已通过
    18
    上传者