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.h> #include <string.h> struct DValue { long measure; int seat; char *pc; struct DValue *next; }; /* int error() { cout << "Input Error" << endl; return 1; } */ struct DValue *creat(int m, int n) { struct DValue *head, *pb, *pf; head = NULL; int i; for(i=0;i<m;i++) { pb = new struct DValue; pb->pc = new char[n+1]; cin >> pb->pc; /* if((int)strlen(pb->pc) > n) return NULL; for(j=0;j<m;j++) { switch(pb->pc[j]) { case 'A': case 'C': case 'G': case 'T': break; default: return NULL; } } */ if(i==0) head = pb; else pf->next = pb; pb->next = NULL; pf = pb; } return(head); } void getmeasure(struct DValue *head, int n) { int i,j; struct DValue *pb = head; pb->measure = 0; for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(pb->pc[i] > pb->pc[j]) pb->measure++; } void getseat(struct DValue *head, int m) { struct DValue *pb = head; int temp,i,j; long *pa = new long[m]; for(i=0;i<m;i++) { pa[i] = pb->measure; pb = pb->next; } for(i=0;i<m-1;i++) for(j=i+1;j<m;j++) if(pa[i] > pa[j]) { temp = pa[i]; pa[i] = pa[j]; pa[j] = temp; } pb = head; while(pb != NULL) { for(i=0;i<m;i++) if(pb->measure == pa[i]) { pb->seat = i; break; } pb = pb->next; } } int main() { int m,n,i; // cout << "Input:" << endl; cin >> n >> m; /* if(n <= 0 || m <= 0) return(error()); */ struct DValue *head,*pb; head = creat(m,n); /* if(NULL == head) return(error()); */ pb = head; while(pb != NULL) { getmeasure(pb,n); pb = pb->next; } getseat(head,m); // cout << "Ouput:" << endl; for(i=0;i<m;i++) { pb = head; while(pb != NULL) { if(pb->seat == i) { cout << pb->pc << endl; break; } pb = pb->next; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator