Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.CodeDom.Compiler;
- using System.Collections.Generic;
- using System.Collections;
- using System.ComponentModel;
- using System.Diagnostics.CodeAnalysis;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Runtime.Serialization;
- using System.Text.RegularExpressions;
- using System.Text;
- using System;
- class Result
- {
- /*
- * Complete the 'diagonalDifference' function below.
- *
- * The function is expected to return an INTEGER.
- * The function accepts 2D_INTEGER_ARRAY arr as parameter.
- */
- public static int diagonalDifference(List<List<int>> arr)
- {
- int sor = 0,
- oszlop = arr.Count,
- al = 0,
- be = 0;
- foreach(List<int> line in arr) sor++;
- for(int i = 0; i <= sor; i++){
- for(int ali = 0; ali < arr.Count; ali++){
- if(i == ali)
- al += arr[i][ali];
- }
- for(int bei = arr.Count; bei >= 0; bei--){
- if(i + bei == arr.Count)
- be += arr[i][bei];
- }
- }
- return Math.Abs(al - be);
- }
- }
- class Solution
- {
- public static void Main(string[] args)
- {
- TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
- int n = Convert.ToInt32(Console.ReadLine().Trim());
- List<List<int>> arr = new List<List<int>>();
- for (int i = 0; i < n; i++)
- {
- arr.Add(Console.ReadLine().TrimEnd().Split(' ').ToList().Select(arrTemp => Convert.ToInt32(arrTemp)).ToList());
- }
- int result = Result.diagonalDifference(arr);
- textWriter.WriteLine(result);
- textWriter.Flush();
- textWriter.Close();
- }
- }
- /*ERROR
- Unhandled Exception:
- System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
- Parameter name: index
- at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x00009] in <04750267503a43e5929c1d1ba19daf3e>:0
- at Result.diagonalDifference (System.Collections.Generic.List`1[T] arr) [0x000b2] in solution.cs:40
- at Solution.Main (System.String[] args) [0x0008e] in solution.cs:62
- [ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
- Parameter name: index
- at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x00009] in <04750267503a43e5929c1d1ba19daf3e>:0
- at Result.diagonalDifference (System.Collections.Generic.List`1[T] arr) [0x000b2] in solution.cs:40
- at Solution.Main (System.String[] args) [0x0008e] in solution.cs:62
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement