Created
January 14, 2016 18:29
-
-
Save liango2/63cd4443a60361ec140c to your computer and use it in GitHub Desktop.
DiagonalDifference
This file contains hidden or 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
object Solution { | |
def main(args: Array[String]) { | |
val sc = new java.util.Scanner(System.in); | |
var n = sc.nextInt(); | |
var a = Array.ofDim[Int](n, n); | |
for (a_i <- 0 to n - 1) { | |
for (a_j <- 0 to n - 1) { | |
a(a_i)(a_j) = sc.nextInt(); | |
} | |
} | |
val v1 = (for (i <- 0 to n - 1; j <- 0 to n - 1 if i == j) yield a(i)(j)).sum | |
val v2 = (for (i <- 0 to n - 1; j <- n-1 to 0 by -1 if i + j == n - 1) yield a(i)(j)).sum | |
println(math.abs(v1 - v2)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment