-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjsBoilerplate.js
More file actions
66 lines (54 loc) · 1.46 KB
/
jsBoilerplate.js
File metadata and controls
66 lines (54 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* please explain approach to the problem, so to help others like me
*/
process.stdin.resume();
process.stdin.setEncoding('ascii');
/*
* initialize globale vars
*/
var input = '';
/*
* read inputs from the command line
*/
process.stdin.on('data', function (data) {
input += data;
});
/*
* finish reading inputs from command line
* 1. process inputs for necessary correct types and values
* 2. pass necessary inputs into solver params to solve
*/
process.stdin.on('end', function () {
// probably should modify processInput with care
var processed = processInput(input);
solver(processed);
});
/*
* actual code with standard output go into here to solve problem
* 'args' is a javascript dict {}
*/
function solver(args) {
// YOUR MAIN CODE STARTS HERE
}
/*================ generic helpers for most problems =================*/
/*
* process all the raw input from command line
* should modify with care
*/
function processInput(input) {
var lines = input.split('\n');
var testCaseNum = parseInt(lines[0]);
var numericInputs = [];
lines.splice(0, 1);
lines.forEach( function (num) {
numericInputs.push(parseInt(num));
});
return { 'testCaseNum' : testCaseNum, 'inputs' : numericInputs }
}
/*
* put print out debug code into here
* call debug() in solver to print
*/
function debug() {
}
/*================ helpers for this specific problem =================*/