#include <iostream>
#include <cmath>
using namespace std;
class polynominal {
int a,b,c;
public :
polynominal( int a,int b,int c) : a( a) ,b( b) ,c( c) { }
void Write( ) { //перший метод
if ( ( b>= 0 ) and ( c>= 0 ) ) {
cout << a<< "x²+" << b<< "x+" << c<< endl;
}
else {
if ( ( b< 0 ) and ( c>= 0 ) ) {
cout << a<< "x²" << b<< "x+" << c<< endl;
}
else {
if ( ( b>= 0 ) and ( c< 0 ) ) {
cout << a<< "x²+" << b<< "x" << c<< endl;
}
else {
cout << a<< "x²" << b<< "x" << c<< endl;
}
}
}
}
double Solve( ) { //другий метод
if ( ( b* b<= 4 * a* c) or ( a== 0 ) ) {
cout << "no real solution" << endl;
return 0 ;
}
else {
double x,y;
x= ( - b+ sqrt ( b* b- 4 * a* c) ) / ( 2 * a) ;
cout << x<< endl;
y= ( - b- sqrt ( b* b- 4 * a* c) ) / ( 2 * a) ;
cout << y<< endl;
return x;
}
}
void form( ) { //третій метод
if ( ( b* b<= 4 * a* c) or ( a== 0 ) ) {
cout << "cannot form because no real roots" << endl;
}
else {
double x,y;
x= ( - b+ sqrt ( b* b- 4 * a* c) ) / ( 2 * a) ;
y= ( - b- sqrt ( b* b- 4 * a* c) ) / ( 2 * a) ;
if ( ( x>= 0 ) and ( y>= 0 ) ) {
cout << a<< "(x-" << x<< ")(x-" << y<< ")" << endl;
}
else {
if ( ( x< 0 ) and ( y>= 0 ) ) {
cout << a<< "(x+" << abs ( x) << ")(x-" << y<< ")" << endl;
}
else {
if ( ( x>= 0 ) and ( y< 0 ) ) {
cout << a<< "(x-" << x<< ")(x+" << abs ( y) << ")" << endl;
}
else {
cout << a<< "(x+" << abs ( x) << ")(x+" << abs ( y) << ")" << endl;
}
}
}
}
}
} ;
int main( ) {
polynominal p( 3 ,4 ,6 ) ,f( 0 ,5 ,2 ) ,g( 3 ,4 ,- 6 ) ;
p.Write ( ) ;
p.Solve ( ) ;
p.form ( ) ;
f.Write ( ) ;
f.Solve ( ) ;
f.form ( ) ;
g.Write ( ) ;
g.Solve ( ) ;
g.form ( ) ;
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNsYXNzIHBvbHlub21pbmFsIHsKICAgIGludCBhLGIsYzsKICAgIHB1YmxpYzoKICAgIHBvbHlub21pbmFsKGludCBhLGludCBiLGludCBjKSA6IGEoYSksYihiKSxjKGMpIHt9CiAgICB2b2lkIFdyaXRlKCkgey8v0L/QtdGA0YjQuNC5INC80LXRgtC+0LQKICAgICAgICBpZiAoKGI+PTApIGFuZCAoYz49MCkpIHsKICAgICAgICAgICAgY291dDw8YTw8InjCsisiPDxiPDwieCsiPDxjPDxlbmRsOwogICAgICAgIH0KICAgICAgICBlbHNlIHsKICAgICAgICAJaWYgKChiPDApIGFuZCAoYz49MCkpIHsKICAgICAgICAJCWNvdXQ8PGE8PCJ4wrIiPDxiPDwieCsiPDxjPDxlbmRsOwogICAgICAgIAl9CiAgICAgICAgCWVsc2UgewogICAgICAgIAkJaWYgKChiPj0wKSBhbmQgKGM8MCkpIHsKICAgICAgICAJCQljb3V0PDxhPDwieMKyKyI8PGI8PCJ4Ijw8Yzw8ZW5kbDsKICAgICAgICAJCX0KICAgICAgICAJCWVsc2UgewogICAgICAgIAkJCWNvdXQ8PGE8PCJ4wrIiPDxiPDwieCI8PGM8PGVuZGw7CiAgICAgICAgCQl9CiAgICAgICAgCX0KICAgICAgICB9CiAgICB9CiAgICBkb3VibGUgU29sdmUoKSB7Ly/QtNGA0YPQs9C40Lkg0LzQtdGC0L7QtAogICAgCWlmICgoYipiPD00KmEqYykgb3IgKGE9PTApKSB7CiAgICAJCWNvdXQ8PCJubyByZWFsIHNvbHV0aW9uIjw8ZW5kbDsKICAgIAkJcmV0dXJuIDA7CiAgICAJfQogICAgCWVsc2UgewogICAgCQlkb3VibGUgeCx5OwogICAgCQl4PSgtYitzcXJ0KGIqYi00KmEqYykpLygyKmEpO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