MiroslavKisov

DiagonalDifference

Jan 28th, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace DiagonalDifference
  5. {
  6.     public class StartUp
  7.     {
  8.         public static void Main(string[] args)
  9.         {
  10.             var N = int.Parse(Console.ReadLine());
  11.             long[,] matrix = new long[N, N];
  12.             long sumPrimary = 0;
  13.             long sumSecondary = 0;
  14.             long difference = 0;
  15.             for (int i = 0; i < matrix.GetLength(0); i++)
  16.             {
  17.                 var line = Console.ReadLine()
  18.                     .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
  19.                     .Select(int.Parse)
  20.                     .ToArray();
  21.                 for (int j = 0; j < matrix.GetLength(1); j++)
  22.                 {
  23.                     matrix[i, j] = line[j];
  24.                 }
  25.             }
  26.             for (int i = 0, j = 0, k = 0; i < N; i++, j++, k++)
  27.             {
  28.                 sumPrimary += matrix[j, k];
  29.             }
  30.             for (int i = 0, j = 0, k = N - 1; i < N; i++, j++, k--)
  31.             {
  32.                 sumSecondary += matrix[j, k];
  33.             }
  34.             difference = sumPrimary - sumSecondary;
  35.             Console.WriteLine(Math.Abs(difference));
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment