Language: C++

#include<iostream>
#include<string>
#include<cmath>
using namespace std;

char equation[100];
int element[100][5];
int i,j,l,left_begin,left_end,right_begin,right_end,sum,sum_term,sum_term_left,sum_term_right,sum_element,present,aim,pre,ai,term,p,p1,p2,same,now,x,y,xx,xy,xz,t;
int k,fenzi,fenmu,fz,fm,ii,t1,t2,tt,temp,f1,f2,det,dd,tx;
string st;

void simplify(int &x,int &y)
{
	if ((x<0)&&(y<0)||(x>0)&&(y<0)) {
		x=-x;
		y=-y;
	}
}

int gcd(int x,int y)
{
   if(y==0)return x;
	return gcd(y,x%y);
}

int gmd(int x,int y)
{

	return x*y/gcd(x,y);
}

int main()
{
	int count[100][100],equation_group[100][100][5],solve[100][5];
	while (true) {
		cin>>st;
		if(st[0]=='.')break;
		l=st.length();
		for (i=0;i<=l-2;i++) equation[i+1]=st[i];
		i=1;
		while (equation[i]!='-') i++;
		left_begin=1;
		left_end=i-1;
		right_begin=i+2;
		right_end=l-1;
		sum=0;
		for (i=left_begin;i<=left_end;i++) if (equation[i]=='+') sum++;
		sum_term=sum+1;
		sum_term_left=sum+1;
		sum=0;
		for (i=right_begin;i<=right_end;i++) if (equation[i]=='+') sum++;
		sum_term+=sum+1;
		sum_term_right=sum+1;
		sum_element=0;
		term=0;
		i=1;
		while (i<=left_end) {
			present=i;
			while ((i<=left_end)&&(equation[i]!='+')) i++;
			if (i==left_end+1) aim=i-1;
			else {i--;aim=i;}
			term++;
			while (present<=aim) {
				if ((equation[present]>=65)&&(equation[present]<=90)) {
					if ((equation[present+1]>=97)&&(equation[present+1]<=122)) {
						p1=equation[present];
						p2=equation[present+1];
						p=2;
					}
					else {
						p1=equation[present];
						p2=0;
						p=1;
					}
					same=0;
					for (j=1;j<=sum_element;j++) if ((p1==element[j][1])&&(p2==element[j][2])) {
						same=1;
						now=j;
					}
					if (same==0) {
						sum_element++;
						element[sum_element][1]=p1;
						element[sum_element][2]=p2;
						now=sum_element;
					}
					if (p==1) j=present+1;
					else if (p==2) j=present+2;
					if ((equation[j]>=48)&&(equation[j]<=57)) {
						x=0;
						while ((j<=aim)&&(equation[j]>=48)&&(equation[j]<=57)) {
							x=x*10+equation[j]-48;
							j++;
						}
					}
					else x=1;
					if (same==0) count[term][now]=x;
					else count[term][now]+=x;
				}
				else if (equation[present]=='(') {
					xx=present+1;
					while (equation[xx]!=')') xx++;
					xy=xx+1;
					if ((equation[xy]>=48)&&(equation[xy]<=57)) {
						y=0;
						while ((xy<=aim)&&(equation[xy]>=48)&&(equation[xy]<=57)) {
							y=y*10+equation[xy]-48;
							xy++;
						}
					}
					else y=1;
					pre=present;
					present++;
					aim=xx-1;
					while (present<=aim) {
						if ((equation[present]>=65)&&(equation[present]<=90)) {
							if ((equation[present+1]>=97)&&(equation[present+1]<=122)) {
								p1=equation[present];
								p2=equation[present+1];
								p=2;
							}
							else {
								p1=equation[present];
								p2=0;
								p=1;
							}
							same=0;
							for (j=1;j<=sum_element;j++) if ((p1==element[j][1])&&(p2==element[j][2])) {
								same=1;
								now=j;
							}
 							if (same==0) {
								sum_element++;
								element[sum_element][1]=p1;
								element[sum_element][2]=p2;
								now=sum_element;
							}
							if (p==1) j=present+1;
							else if (p==2) j=present+2;
							if ((equation[j]>=48)&&(equation[j]<=57)) {
								x=0;
								while ((j<=aim)&&(equation[j]>=48)&&(equation[j]<=57)) {
									x=x*10+equation[j]-48;
									j++;
								}
							}
							else x=1;
						if (same==0) count[term][now]=x*y;
						else count[term][now]+=x*y;
						}
				 		present++;
					}
					present=pre;
					aim++;
				}
				if (equation[present]=='(') present=xy;
				else present++;
			}
			i=i+2;
		}
		i=left_end+3;
		while (i<=right_end) {
			present=i;
			while ((i<=right_end)&&(equation[i]!='+')) i++;
			if (i==right_end+1) aim=i-1;
			else {i--;aim=i;}
			term++;
			while (present<=aim) {
				if ((equation[present]>=65)&&(equation[present]<=90)) {
					if ((equation[present+1]>=97)&&(equation[present+1]<=122)) {
						p1=equation[present];
						p2=equation[present+1];
						p=2;
					}
					else {
						p1=equation[present];
						p2=0;
						p=1;
					}
					same=0;
					for (j=1;j<=sum_element;j++) if ((p1==element[j][1])&&(p2==element[j][2])) {
						same=1;
						now=j;
					}
					if (same==0) {
						sum_element++;
						element[sum_element][1]=p1;
						element[sum_element][2]=p2;
						now=sum_element;
					}
					if (p==1) j=present+1;
					else if (p==2) j=present+2;
					if ((equation[j]>=48)&&(equation[j]<=57)) {
						x=0;
						while ((j<=aim)&&(equation[j]>=48)&&(equation[j]<=57)) {
							x=x*10+equation[j]-48;
							j++;
						}
					}
					else x=1;
				if (same==0) count[term][now]=x;
				else count[term][now]+=x;
			}
				else if (equation[present]=='(') {
					xx=present+1;
					while (equation[xx]!=')') xx++;
					xy=xx+1;
					if ((equation[xy]>=48)&&(equation[xy]<=57)) {
						y=0;
						while ((xy<=aim)&&(equation[xy]>=48)&&(equation[xy]<=57)) {
							y=y*10+equation[xy]-48;
							xy++;
						}
					}
					else y=1;
					pre=present;
					present++;
					aim=xx-1;
					while (present<=aim) {
						if ((equation[present]>=65)&&(equation[present]<=90)) {
							if ((equation[present+1]>=97)&&(equation[present+1]<=122)) {
								p1=equation[present];
								p2=equation[present+1];
								p=2;
							}
							else {
								p1=equation[present];
								p2=0;
								p=1;
							}
							same=0;
							for (j=1;j<=sum_element;j++) if ((p1==element[j][1])&&(p2==element[j][2])) {
								same=1;
								now=j;
							}
 							if (same==0) {
								sum_element++;
								element[sum_element][1]=p1;
								element[sum_element][2]=p2;
								now=sum_element;
							}
							if (p==1) j=present+1;
							else if (p==2) j=present+2;
							if ((equation[j]>=48)&&(equation[j]<=57)) {
								x=0;
								while ((j<=aim)&&(equation[j]>=48)&&(equation[j]<=57)) {
									x=x*10+equation[j]-48;
									j++;
								}
							}
							else x=1;
						if (same==0) count[term][now]=x*y;
						else count[term][now]+=x*y;
						}
				 		present++;
					}
					present=pre;
					aim++;
				}
				if (equation[present]=='(') present=xy;
				else present++;
			}
			i=i+2;
		}
		for (i=1;i<=sum_element;i++) {
			for (j=1;j<=sum_term_left;j++) equation_group[i][j][1]=count[j][i];
			for (j=sum_term_left+1;j<=sum_term;j++) equation_group[i][j][1]=-count[j][i];
		}
		for (i=1;i<=sum_element;i++)
			for (j=1;j<=sum_term;j++) equation_group[i][j][2]=1;
		for (i=1;i<=sum_element-1;i++) {
			if (equation_group[i][i][1]==0) {
				ii=i+1;
				while ((ii<=sum_element)&&(equation_group[ii][i][1]==0)) ii++;
				if (ii==sum_element+1) ii--;
				for (j=1;j<=sum_term;j++){
					temp=equation_group[i][j][1];
					equation_group[i][j][1]=equation_group[ii][j][1];
					equation_group[ii][j][1]=temp;
					temp=equation_group[i][j][2];
					equation_group[i][j][2]=equation_group[ii][j][2];
					equation_group[ii][j][2]=temp;
				}
			}
			for (j=i+1;j<=sum_element;j++) if (equation_group[j][i][1]!=0) {
				fenzi=equation_group[j][i][1]*equation_group[i][i][2];
				fenmu=equation_group[i][i][1]*equation_group[j][i][2];
				simplify(fenzi,fenmu);
				for (k=1;k<=sum_term;k++) {
					f1=fenzi*equation_group[i][k][1];
					f2=fenmu*equation_group[i][k][2];
					simplify(f1,f2);
					fm=gmd(abs(f2),abs(equation_group[i][k][2]));
					t1=fm/equation_group[j][k][2];
					t2=fm/f2;
					fz=equation_group[j][k][1]*t1;
					f1=f1*t2;
					f2=f2*t2;
					det=f1-fz;
					if (det!=0) {
						tt=gcd(abs(det),fm);
						det=det/tt;
						fm=fm/tt;
					}
					else fm=1;
					simplify(det,fm);
					equation_group[j][k][1]=det;
					equation_group[j][k][2]=fm;
				}
			}
		}
		solve[sum_term][1]=1;
		solve[sum_term][2]=1;
		tx=0;
		for (i=sum_element;i>=1;i--) {
			sum=0;
			for (j=1;j<=sum_term;j++) sum+=equation_group[i][j][1]*equation_group[i][j][1];
			if (sum==0) tx++;
		}
		sum_element-=tx;
		for (i=sum_element;i>=1;i--) {
			fm=1;
			fz=0;
			for (j=i+1;j<=sum_term;j++) fm=gmd(fm,abs(solve[j][2]*equation_group[i][j][2]));
			for (j=i+1;j<=sum_term;j++) {
				fenmu=solve[j][2]*equation_group[i][j][2];
				t=fm/fenmu;
				fz+=t*solve[j][1]*equation_group[i][j][1];
			}
			fz=-fz;
			if (fz!=0) {
				tt=gcd(abs(fz),fm);
				fz=fz/tt;
				fm=fm/tt;
			}
			fenzi=fz*equation_group[i][i][2];
			fenmu=fm*equation_group[i][i][1];
			simplify(fenzi,fenmu);
			if (fenzi!=0){
				tt=gcd(fenzi,fenmu);
				fenzi=fenzi/tt;
				fenmu=fenmu/tt;
			}
			solve[i][1]=fenzi;
			solve[i][2]=fenmu;
		}
		dd=solve[1][2];
		for (i=2;i<=sum_term;i++) dd=gmd(dd,solve[i][2]);
		for (i=1;i<=sum_term;i++) {
			t=dd/solve[i][2];
			solve[i][1]*=t;
		}
		for (i=1;i<=sum_term;i++) if (i==1) cout<<solve[i][1];
										  else cout<<' '<<solve[i][1];
		cout<<endl;		
		st.clear();
		/*cin>>st;
		l=st.length();
		*/
		for (i=0;i<=99;i++)
			for (j=0;j<=4;j++) {
				solve[i][j]=0;
				element[i][j]=0;
			}
		for (i=0;i<=99;i++)
			for (j=0;j<=99;j++) count[i][j]=0;
		for (i=0;i<=99;i++) equation[i]=0;
		for (i=0;i<=99;i++)
			for (j=0;j<=99;j++)
				for (k=0;k<=4;k++) equation_group[i][j][k]=0;
				
	}
	return 0;
}

Compiler output:
a.cc:35:1: error: stray '\1' in program
   35 | <U+0001>        while (true) {
      | ^~~~~~~~