- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define e if
#define h while
#define s return
#define v NULL
#define r else
#define u case
#define C switch
#define D for
#define L0 typedef
#define L int
L0 char S;L0 S*Z;L0 Z*U;L0 double N;
L0 struct Q{L Z;union{N b;S c;}M;struct Q*w;struct Q*q;}Q;
Q*K(L w){Q*n=(Q*)malloc(sizeof(Q));e(v==n)exit(1);n->Z=w;s n;}
void A(Z g,U t){h(' '==*g)g++;*t=g;}
Q*V(Z g,U t){Q*n=K(2);n->M.b=strtod(g,t);s n;}
Q*I(Z g,U t){e('+'!=*g)s v;Q*n=K(1);n->M.c='+';++*t;s n;}
Q*W(Z g,U t){e('x'!=*g)s v;Q*n=K(20);g++;e(*g<'0'||*g>'9'){n->M.b=1;*t=g;}r{n->M.b=strtod(g,t);e(*t==g)n->M.b=1;}s n;}
Q*J(Z g,U t){Q*n,*p=v;h(*g){A(g,&g);Q*l=V(g,&g);A(g,&g);Q*m=W(g,&g);Q*o;e(v==m)o=l;r{o=K(1);o->M.c='*';o->w=l;o->q=m;}e(v==p)n=o;r{p->w=n;p->q=o;n=p;}A(g,&g);p=I(g,&g);e(v==p){*t=g;s n;}}}
Q**E(Z g){L n=1,i;Z t=g;h(*t){e(';'==*t)n++;t++;}Q**R=(Q**)malloc((n+1)*sizeof(Q*));e(v==R)s v;D(i=0;i<n;++i){R[i]=J(g,&g);e(*g!=';'&&*g!=0)s v;e(v==R[i])s v;g++;}R[n]=v;s R;}
N P(Q*I,N a){C(I->Z){u 1:C(I->M.c){u '+':s P(I->w,a)+P(I->q,a);u '*':s P(I->w,a)*P(I->q,a);u '/':s P(I->w,a)/P(I->q,a);u '-':s P(I->w,a)-P(I->q,a);}u 2:s I->M.b;u 20:s pow(a,I->M.b);}}
N O(Q*I){N x=0,y=1,z=2,Z=P(I,x),X=P(I, y),H=P(I,z),j=1e-10;L i;D(i=0;i<100&&fabs(z-y)>j&&fabs(x-y)>j&&fabs(X)>j;i++){e(Z*X<0){z=y;H=X;}r e(H*X<0){x=y;Z=X;}r{N d=z-x;x=x-d;z=z+d;Z=P(I,x);X=P(I,y);}y=(z+x)/2;X=P(I,y);}s y;}
Z B(Q**A){L n=0,i,j,d=0;D(;A[n]!=v;n++);Z M=(Z)malloc(n*10+1);e(v==M)s v;D(i=0;A[i]!=v;i++)D(j=0;j<10;j++){
M[i*10+j-d]=(S)fmod(12.51*O(A[i])+j*17,256);
e(!M[i*10+j-d])d++;}M[n*10-d]=0;s M;}
L T(Z g,Z M){Z k=M;h(*g){*g++^=*k++;e(!*k)k=M;}s(0);}
L main(void){
Q**n=E("2.0x5+6.2x2+7;0.3x6.1+6x5+1");
L i;
Z k=B(n);
S w[]={-91,-35,97,113,89,37,113,32,28,-10,124,67,93,32,123,70,63,-19,-71,-123,-114,45,109,64,96,57,13,7,-91,0};
T(w,k);
printf("%s\n",w);
}