题解 | #字符串排序#

字符串排序

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

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

int main() 
{
    char str[1000] = "";
    gets(str);
    int len = strlen(str);
    int ch[1000] = {0};
    int k = 0;
    //把A-Z 依次存到ch
    for(int i = 0 ;i < 26;i++)//每趟收集一个字符到ch数组(A-Z)
    {
        for(int j = 0;j < len;j++)
        {
            if(toupper(str[j]) == 'A'+i) 
            {
                ch[k++] = str[j];
            }
        }
    }
    //遍历,改变原数组顺序,打印输出
    k = 0;
    for(int i = 0;i < len;i++)
    {
        if(isalpha(str[i]))
            str[i] = ch[k++];
    }
    printf("%s\n",str);
    return 0;
}


#华为机试题#
全部评论

相关推荐

zhiyog:哈哈哈哈哈哈哈哈哈哈哈哈哈
点赞 评论 收藏
分享
半解316:内容充实,细节需要修改一下。 1,整体压缩为一页。所有内容顶格。 2,项目描述删除,直接写个人工作量 修改完之后还需要建议,可以私聊
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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