Advertisement
Guest User

06. Equal Sum

a guest
Nov 19th, 2022
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4.  
  5. namespace ConsoleApp1
  6. {
  7.     internal class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.  
  12.             int[] input = Console.ReadLine()
  13.                 .Split()
  14.                 .Select(int.Parse)
  15.                 .ToArray();
  16.             if (input.Length == 1)
  17.             {
  18.                 Console.WriteLine($"0");
  19.                 return;
  20.             }
  21.  
  22.             int sumLeft = 0;
  23.             int sumRight = 0;
  24.  
  25.             for (int i = 0; i < input.Length; i++)
  26.             {
  27.  
  28.                 for (int j = 0; j < input.Length; j++)
  29.                 {
  30.                    
  31.                     if (input[i] > input[j])
  32.                     {
  33.                         sumLeft += input[j];
  34.                     }
  35.                     else if (input[i] < input[j])
  36.                     {
  37.                         sumRight += input[j];
  38.                     }
  39.                     else if (input[i] == input[j])
  40.                     {
  41.                         //Ако са еднакви числа едно след друго задачата се обърква и вади грешен вход.
  42.                     }
  43.                 }
  44.  
  45.                 if (sumLeft == sumRight)
  46.                 {
  47.                     Console.WriteLine(input[i]);
  48.                     return;
  49.                 }
  50.                
  51.  
  52.                 sumLeft = 0;
  53.                 sumRight = 0;
  54.             }
  55.  
  56.             Console.WriteLine($"no");
  57.  
  58.         }
  59.     }
  60. }
  61.  
  62.  
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement