题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723
#include <stdio.h> #include <string.h> #define N 1010 char s[N][110]; void sortString(char s[][110], int n) { for (int i = 0; i < n - 1; i ++ ) { for (int j = 0; j < n - 1 - i; j ++ ) { if (strcmp(s[j], s[j + 1]) > 0) { char temp[110]; strcpy(temp, s[j]); strcpy(s[j], s[j + 1]); strcpy(s[j + 1], temp); } } } } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i ++ ) scanf("%s", s[i]); sortString(s, n); for (int i = 0; i < n; i ++ ) printf("%s\n", s[i]); return 0; }