Last active
June 2, 2016 15:28
-
-
Save Merkanto/9222cd6f785e93ec907f40b5b9fdd6e0 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace DiagonalDifference | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var n = int.Parse(Console.ReadLine()); | |
long[][] matrix = new long[n][]; | |
// Filling the Matrix | |
for (int row = 0; row < n; row++) | |
{ | |
matrix[row] = Console.ReadLine().Split().Select(long.Parse).ToArray(); | |
} | |
// Sum the first diagonal of Matrix | |
long firstDiagonalSum = 0; | |
for (int row = 0; row < n; row++) | |
{ | |
for (int col = 0; col < n; col++) | |
{ | |
if (row == col) | |
{ | |
firstDiagonalSum += matrix[row][col]; | |
} | |
} | |
} | |
// Sum the second diagonal of Matrix | |
long secondDiagonalSum = 0; | |
for (int row = 0; row < n; row++) | |
{ | |
for (int col = n - 1; col >= 0; col--) | |
{ | |
if (col == Math.Abs(row - n + 1)) | |
{ | |
secondDiagonalSum += matrix[row][col]; | |
} | |
} | |
} | |
//Console.WriteLine(firstDiagonalSum); | |
//Console.WriteLine(secondDiagonalSum); | |
Console.WriteLine(Math.Abs(firstDiagonalSum - secondDiagonalSum)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment