#8046: 我用複製貼上可是都顯示 OLE?


RainCandy (雨糖)


code:

// a006

#include <iostream>

#include <math.h>

using namespace std;

 

int main()

{

    double a, b, c, discriminant, root_1, root_2;

    while( cin )

    {

        cin >> a >> b >> c;

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

        if ( discriminant > 0 )

        {

            root_1 = ( ( -b ) + sqrt( discriminant ) ) / ( 2 * a );

            root_2 = ( ( -b ) - sqrt( discriminant ) ) / ( 2 * a );

            if ( root_1 == -0)

                root_1 = 0;

            if ( root_2 == -0)

                root_2 = 0;

            if ( root_1 > root_2 )

                cout << "Two different roots x1=" << root_1 << " , x2=" << root_2 << endl;

            else

                cout << "Two different roots x1=" << root_2 << " , x2=" << root_1 << endl;

        }

        else if ( discriminant < 0 )

        {

            cout << "No real root" << endl;

        }

        else

        {

            root_1 = ( -b ) / (2 * a);

            if ( root_1 == -0)

                root_1 = 0;

            cout << "Two same roots x=" << root_1 << endl;

        }

    }

    return 0;

}

 

#8047: Re:我用複製貼上可是都顯示 OLE?


nlhs910200 (測試專用帳號030)


code:

// a006

#include

#include

using namespace std;

 

int main()

{

    double a, b, c, discriminant, root_1, root_2;

    while( cin )

    {

        cin >> a >> b >> c;

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

        if ( discriminant > 0 )

        {

            root_1 = ( ( -b ) + sqrt( discriminant ) ) / ( 2 * a );

            root_2 = ( ( -b ) - sqrt( discriminant ) ) / ( 2 * a );

            if ( root_1 == -0)

                root_1 = 0;

            if ( root_2 == -0)

                root_2 = 0;

            if ( root_1 > root_2 )

                cout << "Two different roots x1=" << root_1 << " , x2=" << root_2 << endl;

            else

                cout << "Two different roots x1=" << root_2 << " , x2=" << root_1 << endl;

        }

        else if ( discriminant < 0 )

        {

            cout << "No real root" << endl;

        }

        else

        {

            root_1 = ( -b ) / (2 * a);

            if ( root_1 == -0)

                root_1 = 0;

            cout << "Two same roots x=" << root_1 << endl;

        }

    }

    return 0;

}

 


把while()裡面的cin拿掉

再把cin>>a>>b>>c丟進去就能AC了 

#8048: Re:我用複製貼上可是都顯示 OLE?


RainCandy (雨糖)


成功了 感激不盡