Advertisement
radidim

06.Equal Sums (C# Shell App Paste)

Dec 31st, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 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. Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
  3. using System;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Collections.Generic;
  7.  
  8. namespace CSharp_Shell
  9. {
  10.  
  11.     public static class Program
  12.     {
  13.         public static void Main()
  14.         {
  15.            int[] arr = Console.ReadLine()
  16.            .Split()
  17.            .Select(int.Parse)
  18.            .ToArray();
  19.            
  20.            int leftSum = 0;
  21.            int rigthSum  = 0;
  22.            
  23.            for(int i = 0;i<arr.Length;i++)
  24.            {
  25.                rigthSum += arr[i];
  26.            }
  27.            
  28.            for(int i=0;i<arr.Length;i++)
  29.            {
  30.                rigthSum -=arr[i];
  31.                
  32.                if(rigthSum == leftSum)
  33.                {
  34.                    Console.WriteLine(i);
  35.                    return;
  36.                    //continue;
  37.                    //break;
  38.                }
  39.                
  40.                leftSum+=arr[i];
  41.            }
  42.            
  43.            Console.WriteLine("no");
  44.            
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement