Viktomirova

09._Left_and_Right_Sum

May 14th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _09._Left_and_Right_Sum
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.             int left = 0;
  11.             int right = 0;
  12.  
  13.             for (int p = 1; p <= n * 2; p++)
  14.             {
  15.                 int num = int.Parse(Console.ReadLine());
  16.  
  17.                 if (p <= n)
  18.                 {
  19.                     left += num;
  20.                 }
  21.                 else
  22.                 {
  23.                     right += num;
  24.                 }
  25.             }
  26.             if (left == right)
  27.             {
  28.                 Console.WriteLine($"Yes, sum = {left}");
  29.             }
  30.             else
  31.             {
  32.                 int diff = Math.Abs(left - right);
  33.                 Console.WriteLine($"No, diff = {diff}");
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment