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 |
求助!测试数据都对,提交上去就是WA。。用数组首位记录逆序数,算法比较低级。。 #include <iostream> using namespace std; int main() { int leng, num; cin >> leng >> num; char** dna = new char*[num]; for(int i = 0; i < num; i++) dna[i] = new char[leng+2]; int row, col; int prev; for(row = 0; row < num; row++){ dna[row][0] = '0'; for(col = 1; col <= leng; col++){ cin >> dna[row][col]; for(prev = 1; prev < col; prev++) if(dna[row][prev] > dna[row][col]) dna[row][0]++; //unsortedness increase; } dna[row][leng+1] = '\0'; } char* temp; //start comparing; for(int j = 0; j < num - 1; j++){ row = num - 1; while(row > j){ if(dna[row][0] < dna[row-1][0]){ temp = dna[row-1]; dna[row-1] = dna[row]; dna[row] = temp; } row--; } } for(row = 0; row < num; row++){ for(col = 1; col <= leng; col++) cout << dna[row][col]; cout << 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