Advertisement
vaakata

EqualSumsMatrix_30.05.2016

May 30th, 2016
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace EqualSums_27._05._2016
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  14.             int l = input.Length;
  15.             int[,] result = new int[2, l];
  16.             int sumLeft = 0;
  17.             int sumRight = 0;
  18.  
  19.             if (input.Length == 1)
  20.             {
  21.                 Console.WriteLine(0);
  22.             }
  23.             else
  24.             {
  25.                 for (int i = 0; i < l; i++)
  26.                 {
  27.                     Array.Clear(result, 0, result.Length);
  28.                     sumLeft = 0;
  29.                     sumRight = 0;
  30.  
  31.                     for (int row = 0; row < result.GetLength(0); row++)
  32.                     {
  33.                         //left numbers
  34.                         if (row == 0 && i > 0)
  35.                         {
  36.                             for (int colLeft = 0; colLeft <= Math.Max(i - 1, 0); colLeft++)
  37.                             {
  38.                                 {
  39.                                     result[row, colLeft] = input[colLeft];
  40.                                     sumLeft += result[row, colLeft];
  41.                                 }
  42.                             }
  43.                         }
  44.                         //right numbers
  45.                         if (row == 1 && i < input.Length - 1)
  46.                         {
  47.                             for (int colRight = i + 1; colRight < l; colRight++)
  48.                             {
  49.                                 result[row, colRight] = input[colRight];
  50.                                 sumRight += result[row, colRight];
  51.                             }
  52.                         }
  53.                     }
  54.  
  55.                     if (sumLeft == sumRight)
  56.                     {
  57.                         Console.WriteLine(i);
  58.                         return;
  59.                     }
  60.                 }
  61.                 Console.WriteLine("no");
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement