node做oj遇到问题,诚恳请教,非常着急,因为要考试了
2017-05-31 1:46:04 来自:尼古拉拉特拉斯 0 人回应
var readline = require("readline");
var rl = readline.createInterface({
    input:process.stdin,
    output:process.stdout
});

var dataLength = 3; // 一组数据的行数


function isIn(item, arr){
    var isIn = false;
    for(var i = 0;i<arr.length;i++){
        if(arr[i]===item){
            isIn = true;
            break;
        }
    }
    return isIn;
}

function order(value1, value2){
    return value1-value2;
}

var inputs = [];
rl.on('line', function(data) {
    // 获取输入
    inputs.push(data.trim());  
});
rl.on("close",function(){
    var res = "";
    var groupLength = inputs.length/dataLength;
    for(var i=0;i<groupLength;i++){
        var oneGroup =[];
        for(var j=i*dataLength;j<dataLength*i+dataLength;j++){
            oneGroup.push(inputs[j]);
        }
        if(i == groupLength-1){
            res=res+handler(oneGroup);
        }else{
            res = res+handler(oneGroup)+"\n";
        }
        //console.log(res,"$$");
    }
    console.log(res);
})

/**
 * [deal description]
 * @param  {[type]} inputs [description]
 * @return {[type]}        [description]
 */
function handler(oneGroup) {
    var result = '';

    var firstLine = oneGroup[0].trim();
        var secondLine = oneGroup[1].trim();
        var thirdLine = oneGroup[2].trim();
        var setOne = secondLine.split(" ").map(function(item,index,arr){
            return parseInt(item.trim());
        });
         var setTwo = thirdLine.split(" ").map(function(item,index,arr){
            return parseInt(item.trim());
        });
        var res = [].concat(setOne);
        for(var i=0; i<setTwo.length;i++){
             if(!isIn(setTwo[i],setOne)){
                res.push(setTwo[i]);
             }
        }

    result = res.sort(order).join(" ");
    return result;
}

 

就是这个样子,本地没有问题,在赛码网总是不过

还没有人回应!

您的回应

你还未登陆,不能回应!登陆