题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
int main() {
    char str[1001];
    //scanf("%s", str);
    gets(str);
    int len = strlen(str);
    char str_ch[1001];
    int index = 0;
    for (char i = 'A'; i <= 'Z'; i++) {
        for (int j = 0; j < len; j++) {
            if (str[j] == i || str[j] - 32 == i) {
                str_ch[index++] = str[j];
            }
        }
    }
    index = 0;
    for (int i = 0; i < len; i++) {
        if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')) {
            printf("%c", str_ch[index++]);
        } else {
            printf("%c", str[i]);
        }
    }
    return 0;
}
排行榜92
查看30道真题和解析