题解 | #图片整理#
图片整理
http://www.nowcoder.com/practice/2de4127fda5e46858aa85d254af43941
题目要是这么简单sort内置方法,估计出题人他希望用更加基础的方式来了解你的排序基础,所以大家还是自己实现排序
简单粗暴不加班法
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.on("line", function (line) {
console.log(line.split('').sort().join(''))
});
冒泡法
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.on("line", function (line) {
const lines = line.split("");
for (let i = 0; i < lines.length; i++) {
for (let j = 1; j < lines.length-i; j++) {
if (lines[j].charCodeAt() <lines[j-1].charCodeAt()) {
const temp = lines[j-1];
lines[j-1] = lines[j];
lines[j] = temp;
}
}
}
console.log(lines.join(''));
});