Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:晒一下c++味道比较足的代码In Reply To:晒一下c++味道比较足的代码 Posted by:osfpu at 2012-03-03 12:32:48 > 一次AC,代码如下: > ////////////////////////////////// > #include<iostream> > #include<algorithm> > #include<string> > #include<vector> > //#include<cstdlib> > using namespace std; > struct DNA > { > string seq; //dna sequence > int inver; //unsortedness > int order; //the order of input > DNA() > { > inver = 0; > } > }; > bool cmp(DNA a, DNA b) > { > if(a.inver < b.inver) > { > return true; > } > else if((a.inver == b.inver) && (a.order < b.order)) > { > return true; > } > else > { > return false; > } > } > void print(DNA a) > { > cout<<a.seq<<endl; > } > int main() > { > int n,m,i = 0; > vector<DNA> dvec; > cin>>n>>m; > while(i++ < m) > { > DNA dt; > dt.order = i; > cin>>dt.seq; > dvec.push_back(dt); > } > for(vector<DNA>::iterator diter = dvec.begin() > ; diter != dvec.end(); diter++) > { > for(string::iterator si1 = diter->seq.begin() > ;si1 != diter->seq.end(); si1++) > { > for(string::iterator si2 = si1 > ;si2 != diter->seq.end(); si2++) > { > if(*si1 > *si2) > { > ++(diter->inver); > } > } > } > } > sort(dvec.begin(),dvec.end(),cmp); > for_each(dvec.begin(),dvec.end(),print); > // system("PAUSE"); > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator