题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 1.声明字符串数组,获取字符串
// 2.对字符串指针进行排序,使用strcmp
// 3.输出字符串
// 4.释放内存
int mycopm(const void *p1, const void *p2)
{
const char *a = *((const char* *) p1);
const char *b = *((const char* *) p2);
return strcmp(a, b);
}
int main() {
int n = 0;
scanf("%d", &n);
char *str[n];
for(int i = 0; i < n; ++i)
{
str[i] = (char *)calloc(110, sizeof(char));
scanf("%s", str[i]);
}
qsort(str, n, sizeof(char *), mycopm);
for(int i = 0; i < n; ++i)
{
puts(str[i]);
free(str[i]);
}
return 0;
}

安克创新 Anker公司福利 911人发布