题解 | #字符串排序#

字符串排序

https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584

#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main() {
    char str[1001];
    fgets(str, sizeof(str), stdin);
    char newstr[1001];
    int len = strlen(str);
    int newstrIndex = 0;
    int strIndex = 0;
    for(int i = 0; i < 26; i++) {
        for(int j = 0; j < len; j++) {
            while(!isalpha(str[newstrIndex]) && newstrIndex < len) {
                newstr[newstrIndex] = str[newstrIndex];
                newstrIndex++;
            }
            if(str[j] == 'a' + i || str[j] == 'A' + i) {
                newstr[newstrIndex] = str[j];
                newstrIndex++;
            }
        }
    }
    newstr[newstrIndex] = '\0';

    printf("%s\n", newstr);
    return 0;
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务