#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
static int compare (void const *a, void const *b)
{
char const *const *pa = a;
char const *const *pb = b;
if(strlen(*pa) == strlen(*pb))
return strcmp(*pa, *pb);
return strlen(*pa) - strlen(*pb);
}
int main(){
int nbr;
scanf("%d", &nbr);
char **tab = malloc(sizeof(char*) * nbr);
char *str = (char*)malloc(sizeof(char) * 1000000);
for(int i = 0; i < nbr; i++)
{
scanf("%s", str);
tab[i] = malloc(sizeof(char) * (strlen(str) + 1));
sprintf(tab[i],"%s",str);
}
qsort(tab, nbr, sizeof(char*), compare);
for(int i = 0; i < nbr; i++)
printf("%sn", tab[i]);
return 0;
}
最后
以上就是谨慎酸奶最近收集整理的关于字符串数组利用qsort排序的全部内容,更多相关字符串数组利用qsort排序内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复