题解 | #句子逆序#
句子逆序
http://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
while(line = readline()) {
var str = line.trim()
var index = str.length
var tempArr = []
var normalScanCount = 0
while(index--) {
var ch = str[index]
if (ch === ' ' && normalScanCount) {
var word = str.substr(index + 1, normalScanCount)
tempArr.push(word)
normalScanCount = 0
} else {
normalScanCount++
if (index === 0) {
tempArr.push(str.substr(0, normalScanCount))
}
}
}
console.log(tempArr.join(' '))
}