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 |
那里出错了呢?调试了好久#include<iostream> #include<vector> #include<string> #include<algorithm> using namespace std; typedef struct { string str ; int unorder ; } item; void init( int n , vector<item> & dna) { for ( int i = 0 ; i < n ; ++ i ) dna[i].unorder = 0 ; } void calcu ( int n , int m , vector<item> & dna) { for ( int i = 0 ; i < m ; ++ i ) for ( int j = 0 ; j < n ; ++ j ) for ( int k = j ; k < n ; ++ k ) if ( dna[i].str[j] > dna[i].str[k] ) dna[i].unorder ++ ; } bool operator< ( item & lhs , item & rhs ) { return ( lhs.unorder < rhs.unorder ) ; } int main() { int n , m ; cin >> n >> m; vector<item> dna; item in ; for ( int i = 0 ; i < m ; ++ i ) { cin >> in.str ; dna.push_back ( in ); } init( m , dna ); calcu( m , n , dna); //写个排序玩玩 item temp; for ( int i = 1 ; i < m ; ++ i ) { temp = dna[i]; int j ; for ( j = i ; j >= 0 ; -- j ) { if ( dna[j] < dna[ j -1 ] ) { dna[j] = dna[j-1]; } else break; } dna[j] =temp ; } ///一直到这里 for ( int i = 0 ; i < m ; ++ i ) cout << dna[i].str << 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