#include <stdio.h> #include<malloc.h> #include<string.h> int main() { int n, i, j, flag; char tmp[101]; //用于存放 scanf("%d", &n); //动态分配二维数组 char** str = (char**)malloc(n * sizeof(char*)); for (i = 0; i < n; i++) str[i] = (char*)malloc(101 * sizeof(char)); for (i = 0; i < n; i++) scanf("%s", str[i]); for (j = n - 1; j >= 1; j--) { flag = 0; for (i = 1; i <= j; i++) { if (strcmp(str[i - 1], str[i]) > 0) { strcpy(tmp, str[i - 1]); strcpy(str[i - 1], str[i]); strcpy(str[i], tmp); flag = 1; } } if (flag == 0) break; } for (i = 0; i < n; i++) printf("%s\n", str[i]); free(str); return 0; }