Quick actions

cmd+k|ctrl+k

Navigation

Languages

Diagonal Difference

Snippet info

Language

Java

Visibility

public

Author

waricoma

Created

2020-02-03T14:41:47Z

Updated

2020-02-03T14:41:47Z

import java.util.Scanner;
import static java.lang.System.*;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(in);
    int n = scan.nextInt();
    int ax = 0;
    int ay = 0;
    int bx = n - 1;
    int by = 0;
    int a = 0;
    int b = 0;
    for (int y = 0; y < n; ++y) {
      for (int x = 0; x < n; ++x) {
        int c = scan.nextInt();
        if (ax == x && ay == y) {
          a += c;
          ++ax;
          ++ay;
        }
        if (bx == x && by == y) {
          b += c;
          --bx;
          ++by;
        }
      }
    }
    out.println(Math.abs(a - b));
  }
}
INFO