Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.78 KB | None | 0 0
  1. using System.CodeDom.Compiler;
  2. using System.Collections.Generic;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Diagnostics.CodeAnalysis;
  6. using System.Globalization;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Reflection;
  10. using System.Runtime.Serialization;
  11. using System.Text.RegularExpressions;
  12. using System.Text;
  13. using System;
  14.  
  15. class Result
  16. {
  17.  
  18.     /*
  19.      * Complete the 'diagonalDifference' function below.
  20.      *
  21.      * The function is expected to return an INTEGER.
  22.      * The function accepts 2D_INTEGER_ARRAY arr as parameter.
  23.      */
  24.  
  25.     public static int diagonalDifference(List<List<int>> arr)
  26.     {
  27.         int sor = 0,
  28.             oszlop = arr.Count,
  29.             al = 0,
  30.             be = 0;
  31.  
  32.         foreach(List<int> line in arr) sor++;
  33.         for(int i = 0; i <= sor; i++){
  34.             for(int ali = 0; ali < arr.Count; ali++){
  35.                 if(i == ali)
  36.                     al += arr[i][ali];
  37.             }
  38.             for(int bei = arr.Count; bei >= 0; bei--){
  39.                 if(i + bei == arr.Count)
  40.                     be += arr[i][bei];
  41.             }
  42.         }
  43.         return Math.Abs(al - be);
  44.     }
  45. }
  46.  
  47. class Solution
  48. {
  49.     public static void Main(string[] args)
  50.     {
  51.         TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
  52.  
  53.         int n = Convert.ToInt32(Console.ReadLine().Trim());
  54.  
  55.         List<List<int>> arr = new List<List<int>>();
  56.  
  57.         for (int i = 0; i < n; i++)
  58.         {
  59.             arr.Add(Console.ReadLine().TrimEnd().Split(' ').ToList().Select(arrTemp => Convert.ToInt32(arrTemp)).ToList());
  60.         }
  61.  
  62.         int result = Result.diagonalDifference(arr);
  63.  
  64.         textWriter.WriteLine(result);
  65.  
  66.         textWriter.Flush();
  67.         textWriter.Close();
  68.     }
  69. }
  70.  
  71. /*ERROR
  72. Unhandled Exception:
  73.  
  74. System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
  75.  
  76. Parameter name: index
  77.  
  78.   at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x00009] in <04750267503a43e5929c1d1ba19daf3e>:0
  79.  
  80.   at Result.diagonalDifference (System.Collections.Generic.List`1[T] arr) [0x000b2] in solution.cs:40
  81.  
  82.   at Solution.Main (System.String[] args) [0x0008e] in solution.cs:62
  83.  
  84. [ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
  85.  
  86. Parameter name: index
  87.  
  88.   at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x00009] in <04750267503a43e5929c1d1ba19daf3e>:0
  89.  
  90.   at Result.diagonalDifference (System.Collections.Generic.List`1[T] arr) [0x000b2] in solution.cs:40
  91.  
  92.   at Solution.Main (System.String[] args) [0x0008e] in solution.cs:62
  93. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement