题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723
#include <stdio.h> #include <string.h> typedef struct { char buf[101]; } str; int main() { str str[1001]; char temp[101]; int num, i, j, k, max = 0, len; scanf("%d", &num); for (i = 0; i < num; i++) { scanf("%s", str[i].buf); } for(i=0;i<num;i++){ for(j=0;j<num;j++){ if(strcmp(str[i].buf, str[j].buf)<=0){ strcpy(temp, str[i].buf); strcpy(str[i].buf, str[j].buf); strcpy(str[j].buf, temp); } } } for (i = 0; i < num; i++) { printf("%s\n", str[i].buf); } return 0; }