题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
#include <stdio.h> #include <string.h> int main() { char str[1002]; fgets(str, sizeof(str), stdin); str[strlen(str) - 1] = '\0'; int len = strlen(str); char new_str[len]; for(int i = 0; i < len; i++){ for(int j = 0; j < 26; j++){ for(int k = 0; k < len; k++){ while(!((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z'))){ new_str[i] = str[i]; i++; } if((str[k] == 97 + j) || (str[k] == 65 + j)){ new_str[i] = str[k]; i++; } } } } printf("%s", new_str); return 0; }