#include #include #include #include #include #include #include using namespace std; typedef struct{ // struct to keep count of each element in molecule string element; int count; }ecp; typedef vector molecule; // define a molecule typedef set::iterator elemit_t; // I will need this // Function to count the number of atomes of element in molecule int countup(const molecule &m,const string &name) { int total=0; for(molecule::const_iterator i = m.begin();i != m.end(); i++) if(i->element == name) total += i->count; return total; } // find the minimum non-zero fractional part and divide by it--recursively void makeints(vector &v) { double min; double junk; vector::iterator i; set fracpart; for(i=v.begin();i!=v.end();i++) if((min=modf(*i,&junk))>0.000001) fracpart.insert(min); if(fracpart.size()>0) { for(i=v.begin();i!=v.end();i++) *i /= *(fracpart.begin()); makeints(v); // keep doing it until no fractions left } } // printmatrix for debugging void printmatrix(string msg,double **mat,int nr,int nc) { #ifdef DEBUG int r,c; cout< left,right; set elements; vector ans; molecule tm; ecp tmp; elemit_t ei; int nelem,nmolec,r,c,diag,sign,np;; double **mat,*tmparray,tmpf;; while((cin>>sign)&&sign) { // read in all of the molecules tm.clear(); cin>>np; while(np-->0) { cin>>tmp.element>>tmp.count; elements.insert(tmp.element); // add element to set of elements tm.push_back(tmp); } if(sign>0) left.push_back(tm); // add to left or right, depending on sign else right.push_back(tm); } nelem = elements.size(); // get total number of elements found nmolec = left.size() + right.size(); // get total number of molecules // Build a matrix and apply Gauss-Jordan mat = new double*[nelem]; // use a plain old array of pointers to arrays for(r=0;r(nmolec-1)) nelem--;// delete extra rows (will be all zero now). for(r=0;r