jas0nhuang

Don't LeetCode Yet - 0 - Usage of LIOJ

Course link
Things to know before LeetCode!

LIOJ Interface

Lidemy OJ: An online judge system based on the open-source OJ project from Qing-Dao University

  1. File I/O using nodejs library readline

    var readline = require('readline');

    var lines = []
    var rl = readline.createInterface({
    input: process.stdin
    });

    // push one line to the array lines
    rl.on('line', function (line) {
    lines.push(line)
    });

    // After all the input, call the solve() function
    rl.on('close', function() {
    solve(lines)
    })
    //-------------------------above using readline to get input---------
    //-------------------------put solution below------------------------
    function solve(lines){
    // solution here
    }
  2. Test the solution on local machine
    Need NodeJS installed to run the code above.
    Recommended practice: write an input file separately (input.txt) and cat out the content then pass (pipe) it to the program (code.js):

    cat input.txt | node code.js
  3. Test the solution online
    I found jsbin quite useful for testing. It’s really easy to use and we can see the result right away.

Project 0

Problem 1001

Just copy past the code!
Use .split() to SPLIT a line into an array.

Problem 1002

SPOILER ALERT! Not Very Smart Solution below!

function solve(lines) {
for (var i=0; i<line s.length;i++){
var tmp = lines[i].split(' ')

if (Number(tmp[0])==Number(tmp[1]) && Number(tmp[1]) === 0){
return
} else if (Number(tmp[0])> Number(tmp[1])){
console.log(Number(tmp[0]))
} else {
console.log(Number(tmp[1]))
}
}
}

It could be better to use variable to store Number(tmp[0]) and Number(tmp[1]). So the code will looks cleaner.
Use === to compare with number 0.

Practice with problem 1003, 1004 and 1010

Just to get familiar with the OJ system.

In problem 1004 Use BigInt() to process BIG numbers.