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