grigorb57

Half Sum Element ccc....

Feb 9th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 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 ConsoleApp20
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             int allSum = 0;
  15.             int biggestNum = 0;
  16.            
  17.             for (int i = 0; i < n; i++)
  18.             {
  19.                 int readNum = int.Parse(Console.ReadLine());
  20.                 allSum += readNum;
  21.                
  22.                 if (biggestNum < readNum)
  23.                 {
  24.                     biggestNum = readNum;
  25.                 }
  26.                
  27.             }
  28.             if (allSum - biggestNum == biggestNum)
  29.             {
  30.                 Console.WriteLine($"Yes Sum = {biggestNum}");
  31.             }
  32.             else if (biggestNum < allSum)
  33.             {
  34.                 Console.WriteLine($"No Diff = {Math.Abs(allSum - biggestNum - biggestNum)}");
  35.             }
  36.             else
  37.             {
  38.                 Console.WriteLine($"No Diff = {biggestNum}");
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment