Don't LeetCode Yet - 7 - NPSC Problems
NPSC = National Problem Solving Contest
- Contest for middle school students. Some problems are easy.
- Problems are interesting.
- Can find all test cases.
- Can know the difficulty via score board.
How to use the test cases of NPSC
cat pa.in | node code.js | diff pa.out -
new line character
xxd
lets you read a file in HEX code. Cool!
Newline character “0d0a” VS “0a” VS “0d”.
Strip them with diff --strip-trailing-cr
.
LIOJ 1008
Knowledge about binary.(A NUMBER).toString(2)
will give the binary number of A NUMBER
. This problem is actually trying to find how many 1s in a binary number. And this made me think about problem 1014
LIOJ 1009
Simple reverse
Write function your self or use the built-in .reverse
method.
LIOJ 1013
Fibonacci number
code on Wikipedia
function fibon(n) { |
LIOJ 1014
Nonary system (counting without nine).
parseInt(NUMBER, BASE)parsInt(100, 9) == 81
Nonary 100 = 9^ 0* 0 + 9^ 1* 0 + 9^ 2* 1parsInt(33, 9) == 30
Nonary 33 = 9^ 0* 3 + 9^ 1* 3
LIOJ 1016
For this part:
else if(counterA > counterB){ |
We can replace it with “conditional (ternary) operator”:
else{ |