Created
December 5, 2015 04:41
-
-
Save chuck0523/13dc7fd2500da5144231 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lines = []; | |
var readline = require('readline').createInterface(process.stdin, process.stdout); | |
var log = function(x) {console.log(x);}; | |
var parse = function(num) { return parseInt(num, 10); }; | |
var cnt, A, B; | |
var move, dis = 0, pos = 0; | |
readline.on('line', function(line) { | |
lines.push(line); | |
if(lines.length === 1) { | |
data = line.split(' '); | |
cnt = data[0]; | |
A = parse(data[1]); | |
B = parse(data[2]); | |
} else if(lines.length > 1) { | |
move = line.split(' '); | |
move[1] = parse(move[1]); | |
dis = move[1] > B ? B : move[1] < A ? A : move[1]; | |
move[0] === 'East' ? pos += dis : pos -= dis; | |
} | |
if(lines.length - 1 == cnt) { | |
pos > 0 ? log('East ' + pos) : pos < 0 ? log('West ' + Math.abs(pos)) : log(pos); | |
process.exit(0); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment