Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
IPSC 2014 A
var input = [],
s2n = function (s) { return parseInt(s, 10) },
solve = function (r, c, candy_box) {
var result = 0;
for (var i = 0; i < r; i += 1) {
for (var j = 0; j < c; j += 1) {
if (candy_box[i][j] !== 'o')
continue;
if (j > 0 && j < c - 1 && candy_box[i][j - 1] === '>' && candy_box[i][j + 1] === '<') {
result += 1;
}
if (i > 0 && i < r - 1 && candy_box[i - 1][j] === 'v' && candy_box[i + 1][j] === '^') {
result += 1;
}
}
}
return result;
};
require('readline')
.createInterface(process.stdin, {})
.on('line', function(line) {
input.push(line.trim());
}).on('close', function() {
var line = 2, rc;
while (line < input.length) {
rc = input[line++].split(' ').map(s2n);
console.log(solve(rc[0], rc[1], input.slice(line, line + rc[0])));
line += rc[0] + 1;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment