编写程序,输⼊⼀个字符串,然后对字符串的内容(字符)进⾏升序排序,最后输出排序后的新字符串。
• 测试⽤例
• 输⼊:cfa
• 输出:acf
#include <stdio.h>
#include <string.h>
void sort(char* s, int n) {
int i = 0, j = 0, index = 0;
char c;
for (; i < n; i++) {
c = s[i];
index = i;
for (j = i + 1; j < n; j++) {
if (s[j] < c) {
index = j;
c = s[j];
}
}
if (index != i) {
c = s[index];
s[index] = s[i];
s[i] = c;
}
}
}
int main() {
char s[20];
gets(s);
sort(s, strlen(s));
puts(s);
return 0;
}