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 |
一直是runtime error,求大神大虾救命啊~#include<stdio.h> #include<stdlib.h> struct DNA{ char * s; int value; }; int p(struct DNA * a,int low,int high) { int key = a[low].value,p; while(low < high) { while(low < high && a[high].value >= key) { -- high; } p = a[low].value; a[low].value = a[high].value; a[high].value = p; while(low < high && a[low].value <= key) { ++ low; } p = a[high].value; a[high].value = a[low].value; a[low].value = p; } a[low].value = key; return low; } void q(struct DNA * a,int low,int high) { int j; if(low < high) { j = p(a,low,high); q(a,low,j - 1); q(a,j + 1,high); } } int main() { int m,n,i,j,k; while(scanf("%d%d",&m,&n) != EOF) { struct DNA * p; p = (struct DNA *)malloc(sizeof(struct DNA) * n); for(i = 0;i < n;i ++) p[i].s = (char *)malloc(sizeof(char *) * (m + 1)); scanf("%s",p[i].s); p[i].value = 0; for(j = 0;j < m;j ++) for(k = j + 1;k < m;k ++) { if(p[i].s[j] > p[i].s[k]) { p[i].value ++; } } q(p,0,m - 1); for(i = 0;i < n;i ++) printf("%s\n",p[i].s); free(p[i].s); } free(p); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator