Advertisement
radidim

EqualSums.y (C# Shell App Paste)

Oct 5th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
  2. namespace Program
  3. {
  4.     using System;
  5.     using System.Linq;
  6.  
  7.     public class EqualSums
  8.     {
  9.         public static void Main()
  10.         {
  11.             int[] a = Console.ReadLine()
  12.             .Split()
  13.             .Select(int.Parse)
  14.             .ToArray();
  15.             int leftSum=0;
  16.             int rightSum=0;
  17.             for(int i=0; i<a.Length;i++)
  18.             {
  19.                 rightSum+=a[i];
  20.             }
  21.             for(int i=0;i<a.Length;i++)
  22.             {
  23.                 rightSum-=a[i];
  24.            
  25.                 if(leftSum==rightSum)
  26.                 {
  27.                     Console.Write(i);
  28.                     return;
  29.                 }
  30.                 leftSum+=a[i];
  31.                
  32.             }
  33.             Console.Write("no");
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement