Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #define Lmax 256
- using namespace std;
- char s[Lmax],s1[Lmax],s2[Lmax];
- int n;
- long nr1,nr2,nrx1,nrx2;
- void Solve(char *s,long &nr,long &nrx)
- {
- char *p,ss[Lmax];
- long v;
- int semn=1,L;
- strcpy(ss,s);
- p=strtok(ss,"+-");
- nr=0;
- nrx=0;
- while(p)
- {
- L=strlen(p);
- if(p[0]=='x')
- nrx+=semn;
- else
- if(p[L-1]=='x')
- p[L-1]=NULL,v=atol(p),nrx=nrx+semn*v;
- else
- v=atol(p),nr=nr+semn*v;
- if(s[p+L-ss]=='+')
- semn=1;
- else
- semn=-1;
- p=strtok(NULL,"+-");
- }
- }
- int main()
- {
- FILE *f=fopen("ecuatii.in","r");
- FILE *g=fopen("ecuatii.out","w");
- int i;
- char *p;
- fscanf(f,"%d",&n);
- for(i=0;i<n;++i)
- {
- fscanf(f,"%s",s1);
- p=strchr(s1,'=');
- strcpy(s2,p+1);
- *p=NULL;
- Solve(s1,nr1,nrx1);
- Solve(s2,nr2,nrx2);
- if(nrx1==nrx2)
- if(nr1==nr2)
- fprintf(g,"infit\n");
- else
- fprintf(g,"imposibil\n");
- else
- fprintf(g,"%.4lf\n",((double)(nr2-nr1)/(nrx1-nrx2)));
- }
- fclose(f);
- fclose(g);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement