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:我用结构体,然后排序,怎么不行呢In Reply To:我用结构体,然后排序,怎么不行呢 Posted by:xmu0633 at 2009-08-24 22:32:31 > 牛人帮忙看看哈 > #include <iostream> > #include <algorithm> > #include <string> > #include <cstdlib> > using namespace std; > > struct DNA{ > string s; > int num; > }; > struct DNA a[100]; > > int comp(const void *a,const void *b){ > return ((struct DNA*)a)->num > ((struct DNA*)b)->num; > } > > int main(){ > string s; > int num,n,m; > cin>>n>>m; > for(int i=0;i<m;i++){ > num=0; > cin>>a[i].s ; > for(int j=0;j<n-1;j++){ > for(int k=j+1;k<n;k++) > if(a[i].s[j]>a[i].s[k]) > num++; > } > a[i].num=num; > } > qsort(a,m,sizeof(a[0]),comp); > for(int i=0;i<m;i++){ > cout<<a[i].s<<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