const readline = require('readline') //在这里引入
let testGroupNum = 0
let groupList = [] // { num: number, numArr: int[] }
let groupInfo = {}
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
})
let k = -1 //先给行数置-1,表示还没开始读取
let rows = [] //用于存储每行的输入
rl.on('line', function(line) {
if (k < 0) {
k = parseInt(line.trim()) * 2 //读取第一行,得到接下来输入的行数
} else {
rows.push(line.trim()) //将每次输入的行数据存入
let arr = line
.trim()
.split(' ')
.map(function(x) {
return parseInt(x)
})
if (rows.length % 2 === 1) {
groupInfo.num = arr[0] || 0
} else {
groupInfo.numArr = arr
groupList.push(groupInfo)
groupInfo = {} // 重置
}
if (k == rows.length) {
main(groupList)
rows = 0
k = -1
}
}
})
// function exitinput() {
// rl.on('close', function(cmd) {
// // console.log(input.join('\n'))
// process.exit(0)
// })
// }
function main(list) {
const t = +new Date()
for (let i = 0, len = list.length; i < len; i++) {
isInContan(list[i].numArr)
}
process.exit(0)
// console.log('cost', +new Date() - t)
}
// num
function isInContan(arr) {
const min = Math.min.apply(null, arr)
const max = Math.max.apply(null, arr)
if (min == max) {
console.log(min)
return false
}
if (arr.indexOf(0) >= 0) {
console.log('Impossible')
return false
}
let minIndex = arr.indexOf(min)
let maxIndex = arr.indexOf(max)
arr[minIndex] = arr[maxIndex] = max - min
isInContan(arr)
}
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。