题解 | #单词倒排#
单词倒排
https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
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 splitStr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
const splitList = [];
let tempStr = "";
for (let i = 0; i < line.length; i++) {
const t = line[i];
if (splitStr.includes(t)) {
tempStr = tempStr + t;
} else if (tempStr.length > 0) {
splitList.push(tempStr);
tempStr = "";
}
}
if (tempStr.length > 0) {
splitList.push(tempStr);
tempStr = "";
}
// console.log(splitList);
// 倒序
const reverse = splitList.reverse().join(' ')
console.log(reverse)
})();
