We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {
static void Main(String[] args) {
int n = Convert.ToInt32(Console.ReadLine());
int[][] a = new int[n][];
for(int a_i = 0; a_i < n; a_i++){
string[] a_temp = Console.ReadLine().Split(' ');
a[a_i] = Array.ConvertAll(a_temp,Int32.Parse);
}
int value = -1;
IEnumerable<int> Diagonal1= a.Select((x) => x.ElementAt(value +1));
int total1 = 0, total2=0;
foreach (var b in Diagonal1)
{
total1 += b;
value++;
}
int value2 = a.Length;
IEnumerable<int> ans = a.Select((x) => x.ElementAt(value2 - 1));
foreach (var b1 in ans)
{
total2 += b1;
value2--;
}
Console.WriteLine(Math.Abs(total1 - total2));
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Diagonal Difference
You are viewing a single comment's thread. Return to all comments →
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static void Main(String[] args) { int n = Convert.ToInt32(Console.ReadLine()); int[][] a = new int[n][]; for(int a_i = 0; a_i < n; a_i++){ string[] a_temp = Console.ReadLine().Split(' '); a[a_i] = Array.ConvertAll(a_temp,Int32.Parse); } int value = -1;
}