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 |
首次做题一次性AC,发上来聊以纪念,求高手指点#include <iostream> using namespace std; struct DNA{char q[100];int val;}; void QuickSort(DNA *p,int headmark,int tailmark) { if(headmark>=tailmark)//排序区域长度不大于1,不需再排 {return;} DNA temp; int emp,big,small; temp=p[headmark]; small=headmark; big=tailmark; while(small<big) { while(small<big && p[big].val>=temp.val) --big; p[small]=p[big]; while(small<big && p[small].val<=temp.val) ++small; p[big]=p[small]; } emp=big; p[emp]=temp;//定位枢轴值 QuickSort(p,headmark,emp-1); QuickSort(p,emp+1,tailmark); } int main() { int i,j,k,num,len; while(cin>>len>>num) { DNA*p=new DNA[num+1]; for(i=1;i<=num;i++) { cin>>p[i].q; p[i].val=0; for(j=0;j<len;j++) { for(k=j;k<len;k++) if(p[i].q[j]>p[i].q[k])p[i].val++; } } QuickSort(p,1,num); for(i=1;i<=num;i++) cout<<p[i].q<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator