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