| ||||||||||
| 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 | |||||||||
为什么一直runtimeError,求大神帮忙~#include<stdio.h>
#include<string.h>
int checkSort(char *str,int length){
int i,j,count = 0;
for(i=0; i<length-1; i++){
for(j=i+1; j<length; j++){
if((str[i]-str[j])>0){
count++;
}
}
}
return count;
}
void sortStr(int *count,int left,int right,char **str){
int mid = count[left];
int i=left;
int j=right;
int temp;
char *c;
if(right-left<1)
return;
do{
while(i<right&&count[i]<mid){
i++;
}
while(j>left&&count[j]>mid){
j--;
}
if(i<=j){
temp = count[i];
count[i]=count[j];
count[j]=temp;
c = str[i];
str[i]=str[j];
str[j]=c;
i++;
j--;
}
}while(i<=j);
if(i<right){
sortStr(count,i,right,str);
}
if(j>left){
sortStr(count,left,j,str);
}
}
int main(){
int n,m;
char **str;
int *count;
int i;
if(scanf("%d%d",&n,&m)!=EOF){
str = malloc(sizeof(char)*m);
count = malloc(sizeof(int)*m);
for(i=0; i<m; i++){
str[i] = malloc(sizeof(char)*n);
scanf("%s",str[i]);
count[i]=checkSort(str[i],n);
}
sortStr(count,0,m-1,str);
for(i=0; i<m; i++){
printf("%s\n",str[i]);
free(str[i]);
}
free(str);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator