Skip to content

Instantly share code, notes, and snippets.

@breakstorm
Created February 7, 2017 10:23
Show Gist options
  • Save breakstorm/a1252183c9334d55c45075aac1c1b193 to your computer and use it in GitHub Desktop.
Save breakstorm/a1252183c9334d55c45075aac1c1b193 to your computer and use it in GitHub Desktop.
Diagonal Difference
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});
function readLine() {
return input_stdin_array[input_currentline++];
}
/////////////// ignore above this line ////////////////////
function main() {
var n = parseInt(readLine());
var a = [];
var a_sum = 0;
var b_sum = 0;
for(a_i = 0; a_i < n; a_i++){
a[a_i] = readLine().split(' ');
a[a_i] = a[a_i].map(Number);
}
for(i=0; i < n; i++){
a_sum = a_sum + a[i][i];
b_sum = b_sum + a[n-i-1][i];
}
var total = Math.abs(a_sum - b_sum);
console.log(total);
// a = (0,0) + (1,1) + (2,2) ( x+1, y+1 증가)
// b = (0,2) + (1,1) + (2,0) ( x+1, y-1 증가)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment