#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; cerr< 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;; int line=0; while((cin>>sign)&&sign) { // read in all of the molecules line++; if((sign<-1)||(sign>1)) { cerr << "invalid sign on line"<>np)) || np<=0) { cerr << "invalid atom count on line"< 0) { if(!(cin>>tmp.element>>tmp.count) || tmp.count<=0) { cerr<<"invalid atom ["<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 if(nelem == 0 || nmolec == 0) { cerr << "file contains no problem"<(nmolec-1)) nelem--;// delete extra rows (will be all zero now). for(r=0;r