Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Advanced
- {
- class Program
- {
- static void Main(string[] args)
- {
- int dimentions = int.Parse(Console.ReadLine());
- int rows = dimentions;
- int cols = dimentions;
- var matrix = new int[rows, cols];
- for (int row = 0; row < rows; row++)
- {
- var currentRow = Console.ReadLine()
- .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- for (int col = 0; col < cols; col++)
- {
- matrix[row, col] = currentRow[col];
- }
- }
- int primaryRow = 0;
- int primaryCol = 0;
- var primarySum = 0;
- int secondaryRow = matrix.GetLength(0) - 1;
- int secondaryCol = 0;
- var secondarySum = 0;
- while (true)
- {
- if (primaryRow < 0
- || primaryRow >= matrix.GetLength(0)
- || primaryCol < 0
- || primaryCol >= matrix.GetLength(1))
- {
- break;
- }
- primarySum += matrix[primaryRow, primaryCol];
- primaryRow++;
- primaryCol++;
- secondarySum += matrix[secondaryRow, secondaryCol];
- secondaryRow--;
- secondaryCol++;
- }
- Console.WriteLine($"{Math.Abs(primarySum - secondarySum)}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement