kvadrat4o

halfSumElement

Mar 17th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2.  
  3. namespace HalfSumElement
  4. {
  5.     class Program
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             int num;
  10.        
  11.             if (int.TryParse(Console.ReadLine(),out num))
  12.             {      
  13.                     int [] foo  = new int[num];
  14.                
  15.                 for (int i = 0; i < num; i++)
  16.                 {
  17.                     int value;
  18.                     if (int.TryParse(Console.ReadLine(),out value))
  19.                     {
  20.                         foo[i] = value;
  21.                     }  
  22.                     else   
  23.                     {
  24.                         i--;
  25.                     }
  26.                 }
  27.                 int sum = 0;
  28.                 int maxValue =0;
  29.                 bool foundEqual = false;
  30.                 for (int y = 0; y < foo.Length; y++)
  31.                 {
  32.                     if(foo[y] > maxValue)
  33.                     {
  34.                         maxValue = foo[y];
  35.                     }
  36.                     sum +=foo[y];
  37.                 }
  38.                
  39.                 for (int j = 0; j < foo.Length; j++) {
  40.                     int number = foo[j];               
  41.                    
  42.                     if(num * 2 == sum)
  43.                     {
  44.                         foundEqual = true;
  45.                         Console.WriteLine("Yes\n Sum = {0}",sum);
  46.                     }              
  47.                 }
  48.                
  49.                 if(!foundEqual)
  50.                 {
  51.                     Console.WriteLine("No\n Diff = {0}", Math.Abs(maxValue - (sum- maxValue)));
  52.                 }
  53.             }
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment