题解 | #字符串排序#

字符串排序

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;
}

全部评论

相关推荐

07-02 13:50
闽江学院 Java
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-04 14:35
点赞 评论 收藏
分享
06-28 22:48
已编辑
广东金融学院 Java
小浪_Coding:学院本+这俩项目不是buff叠满了嘛
点赞 评论 收藏
分享
下个早班:秒挂就是不缺人
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 14:00
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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