题解 | #图片整理#
图片整理
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(''));
})();

影石Insta360公司氛围 452人发布
查看10道真题和解析