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 |
求助:我选用了稳定的插入排序法,怎么还告诉我是Wrong Answer?我的代码: #include <iostream> using namespace std; char DNAs[100][50]; int nLength, nDNANumber; typedef struct _Measure { int nValue; int nIndex; } Measure; Measure measure[50]; int main() { int i, j, k; //input cin>>nLength>>nDNANumber; for(i = 0; i < nDNANumber; i++) { cin>>DNAs[i]; } //calculate the measurement number for(i = 0; i < nDNANumber; i++) { measure[i].nIndex = i; for(j = 0; j < nLength - 1; j++) { for(k = j + 1; k < nLength; k++) { if(DNAs[i][j] > DNAs[i][k]) { measure[i].nValue++; } } } } //sort the measurement value, we must use a steady sort method //now, I use Insertion Sort Measure temp; int min; for(i = 0; i < nDNANumber - 1; i++) { min = i; for(j = i + 1; j < nDNANumber; j++) { if(measure[min].nValue > measure[j].nValue) { min = j; } } if(min != i) { temp = measure[min]; for(j = min; j > i; j--) { measure[j] = measure[j - 1]; } measure[i] = temp; } } //output the result for(i = 0; i < nDNANumber; i++) { cout<<DNAs[measure[i].nIndex]<<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