// Chem.cc // // Sets up a matrix to solve a system of equations using // "integer" Gaussian elimination #include #include using namespace std; #define FOR(i,a,b) for(int i=a; i T; vector Left; vector Right; string S; //get symbol at S[i] and push it onto T //advance i void GetSym(int &i){ ptype P; string M=""; M += S[i++]; if (isalpha(S[i]) && 'a'<=S[i] && S[i]<='z') M += S[i++]; P.sym = M; P.mult = 1; T.push_back(P); } int GetNum(int &i){ int x=0; x = S[i++]-'0'; while (i=0 && T[i].sym !="("){ T[i].mult *= n; i--; } if(i<0) { //shouldn't happen cout<< "never found ( ********** error *******"<0 && A[a][c-1]<0) || (A[a][a]<0 && A[a][c-1]>0)) { cout <<" No"<0) //only if a is LH if(a>=n){ cout<<" No"<>S; T.clear(); int i=0; while(i Symbols; bool found; //determine # rows by counting symbols Symbols.clear(); int Count = 0; FOR(i,0,Left.size()){ S = Left[i].sym; found = false; FOR(j,0,Symbols.size()) if(Symbols[j] == S) found = true; if(!found){ Count++; Symbols.push_back(S); } } rows = Count; //Build A[rows][cols] int num = 0; FOR(r,0,rows){ S = Symbols[r]; // S is symbol for this row // there are n columns for LHS FOR(c,0,n){ num = 0; //Find symbol S, term c, in Left[] FOR(k,0,Left.size()) if(Left[k].sym == S && Left[k].term == c) { num = Left[k].mult; break; } A[r][c] = num; } // now do the m columns for RHS FOR(c,0,m){ num = 0; //Find symbol S, term c in Right[] FOR(k,0,Right.size()) if(Right[k].sym == S && Right[k].term==c){ num = Right[k].mult; break; } A[r][c+n] = num; } } } // end of BuildA[] int main(){ int x, CaseNo=1; cin>>n>>m; //get # of terms on left and right while(n>0) { Left.clear(); Right.clear(); FOR(i,0,n){ GetT(); EnterLeft(i); //put entries of T into Left } FOR(i,0,m){ GetT(); EnterRight(i); //put entries of T into Right } BuildA(); x = Reduce(rows,cols); //x = # row rank of A[][] cout<<"Case "<>n>>m; } return 0; }