题解 | #明明的随机数#
明明的随机数
http://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
读题认真,主要难度在审题
const readline = require('readline') var rl = readline.createInterface({ input: process.stdin, output: process.stdout }) var result = [] var arr = [] var lineNum = 0 var num = 0 rl.on('line', (line) => { var flag = true // 此时重置 if (num == lineNum) { num = 0 lineNum = parseInt(line) if(arr.length > 0){ result.push(arr) arr = [] } flag = false } // 此时将数据push进数组 if ((num < lineNum) && flag) { num++ if (arr.indexOf(line) < 0) { arr.push(line) } } }) rl.on('close', () => { result.push(arr) result.forEach((res)=>{ res.sort(sortNumber) res.forEach((val) => { console.log(parseInt(val)) }) }) }) function sortNumber(a, b) { return a - b }