题解 | #字符串排序#

字符串排序

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

//菜鸡思路,又复杂又绕
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
    char std1[1001] = { 0 };
    char std2[1001][2] = { 0 };
    char std4[1001]= { 0 };
    fgets(std1,1001,stdin);
    int len = strlen(std1);
    int i = 0;
    int count = 0;
    for (i = 0; i < len; i++)
    {
        if (std1[i] >= 'A' && std1[i] <= 'Z')
        {
            std2[i][0] = std1[i] + 32;
            std2[i][1] = 1;
        }
        else
        {
            std2[i][0] = std1[i];
        }
    }
    int j = 0;
    for (i = 0; i < len;i++)//  BaAb B0Ab B00b 000b 0000
    {
        int record = 0;
        while (std2[record][0] == 0)
        {
            record++;
        }
        if (std2[i][0] < 'a' && std2[i][0]>0 || std2[i][0] > 'z')
        {
            std4[i] = std2[i][0];
            std2[i][0] = 0;
            continue;
        }
        for (j = 0; j < len; j++)
        {
            if (std2[record][0] > std2[j][0]&&std2[j][0]>='a'&& std2[j][0] <= 'z')
            {
                record = j;
            }
        }
        if(std2[record][1])
        std4[i] = std2[record][0]-32;
        else
        std4[i] = std2[record][0];
        std2[record][0] = 0;
    }
    printf("%s", std4);
    return 0;
}

全部评论

相关推荐

码农索隆:想看offer细节
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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