题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/d2f088e655d44e4a85c16f7b99126211
#include <stdio.h>
#include <string.h>
int main() {
char a[20], c;
while ( scanf("%s", &a) != EOF) {
for (int i = 0; i < strlen(a); i++) {
for(int j=0;j<strlen(a)-1-i;j++)
if (a[j] > a[j + 1]) {
c = a[j];
a[j] = a[j + 1];
a[j + 1] = c;
}
}
for (int i = 0; i < strlen(a); i++) {
printf("%c", a[i]);
}
}
return 0;
}
查看3道真题和解析