题解 | #图片整理#

图片整理

https://www.nowcoder.com/practice/2de4127fda5e46858aa85d254af43941

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
    // Write your code here
    const line = await readline();

    const list = [];
    // 字符串分割为数组,并将字符转化为 ASCII 码值保存
    for (let i = 0; i < line.length; i++) {
        const t = line[i];
        const numberT = Number(t);
        if (numberT >= 0 || numberT <= 9) {
            list.push(numberT);
        } else {
            let code = t.charCodeAt(0);
            list.push(code);
        }
    }

    // 对数组排序
    const sortList = list.sort((a, b) => {
        if (a > b) return 1;
        if (a < b) return -1;
        return 0;
    });

    // 将 ASCII 码值还原为字符
    const result = [];
    for (let i = 0; i < sortList.length; i++) {
        const t = sortList[i];
        if (t <= 9) {
            result.push(t);
        } else {
            let char = String.fromCharCode(t);
            result.push(char);
        }
    }
    // 输出结果
    console.log(result.join(''));
})();

全部评论

相关推荐

09-14 20:51
四川大学 Java
慢热的鲸鱼在学习:985加粗就行了,第二个项目来不及准备也没事,省的写了问你你还不会。你只需准备面试八股和项目场景,剩下的交给985。即使面不过也没事,面试经验是最重要的,你现在不缺时间
简历中的项目经历要怎么写
点赞 评论 收藏
分享
牛客96763241...:杭电✌️也是打完招呼,没人回吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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