Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream f("ecuatii.in");
- ofstream g("ecuatii.out");
- char ecuatie[50],semn;
- int delta,k=1,a,b,c;
- int main()
- {
- f.getline(ecuatie,50);
- strcat(ecuatie,"x");
- if(ecuatie[0]=='-')
- {
- if(ecuatie[k]=='x') a=-1;
- else
- {
- while(ecuatie[k]!='x')
- {
- a=a*10+(ecuatie[k]-'0');
- k++;
- }
- a=-a;
- }
- k+=3;
- if(ecuatie[k]=='+') semn='+';
- else semn='-';
- k++;
- if(ecuatie[k]=='0') b=0,k+=2;
- else if(ecuatie[k]=='x')
- {
- if(semn=='+') b=1;
- else b=-1;
- k++;
- }
- else
- {
- while(ecuatie[k]!='x')
- {
- b=b*10+(ecuatie[k]-'0');
- k++;
- }
- if(semn=='-') b=-b;
- k++;
- }
- if(ecuatie[k]=='+') semn='+';
- else semn='-';
- k++;
- if(ecuatie[k]=='0') c=0;
- else
- {
- while(ecuatie[k]!='x')
- {
- c=c*10+(ecuatie[k]-'0');
- k++;
- }
- if(semn=='-') c=-c;
- }
- }
- else
- {
- k=0;
- if(ecuatie[k]=='x') a=1;
- else
- {
- while(ecuatie[k]!='x')
- {
- a=a*10+(ecuatie[k]-'0');
- k++;
- }
- }
- k+=3;
- if(ecuatie[k]=='+') semn='+';
- else semn='-';
- k++;
- if(ecuatie[k]=='0') b=0,k+=2;
- else if(ecuatie[k]=='x')
- {
- if(semn=='+') b=1;
- else b=-1;
- k++;
- }
- else
- {
- while(ecuatie[k]!='x')
- {
- b=b*10+(ecuatie[k]-'0');
- k++;
- }
- if(semn=='-') b=-b;
- k++;
- }
- if(ecuatie[k]=='+') semn='+';
- else semn='-';
- k++;
- if(ecuatie[k]=='0') c=0;
- else
- {
- while(ecuatie[k]!='x')
- {
- c=c*10+(ecuatie[k]-'0');
- k++;
- }
- if(semn=='-') c=-c;
- }
- }
- delta=b*b-4*a*c;
- if(delta<0) g<<-1;
- else
- {
- if(delta==0)
- {
- float radacina=-b/(2*a);
- g<<fixed<<setprecision(2)<<radacina;
- }
- else
- {
- float radacina1, radacina2;
- radacina1=(-b+sqrt(delta))/(2*a);
- radacina2=(-b-sqrt(delta))/(2*a);
- if(radacina1<radacina2) g<<fixed<<setprecision(2)<<radacina1<<" "<<fixed<<setprecision(2)<<radacina2;
- else g<<fixed<<setprecision(2)<<radacina2<<" "<<fixed<<setprecision(2)<<radacina1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement