Advertisement
ivanov_ivan

LeftAndRightSum

Oct 3rd, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 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 LeftRightSum
  8. {
  9.     class SumLeftRight
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.  
  15.             int leftSum = 0;
  16.             int rightSum = 0;
  17.  
  18.             //for(int i = 0; i < n; i++)
  19.             //{
  20.             //    int currentNumber = int.Parse(Console.ReadLine());
  21.             //    leftSum = leftSum + currentNumber;
  22.             //}
  23.  
  24.             //for(int i = 0; i < n; i++)
  25.             //{
  26.             //    int currentNumber = int.Parse(Console.ReadLine());
  27.             //    rightSum = rightSum + currentNumber;
  28.             //}
  29.  
  30.             for(int i = 0; i < 2 * n; i++)
  31.             {
  32.                 if(i < n)
  33.                 {
  34.                     int currentNumber = int.Parse(Console.ReadLine());
  35.                     leftSum = leftSum + currentNumber;
  36.                 }
  37.                 else
  38.                 {
  39.                     int currentNumber = int.Parse(Console.ReadLine());
  40.                     rightSum = rightSum + currentNumber;
  41.                 }
  42.             }
  43.  
  44.             if(leftSum == rightSum)
  45.             {
  46.                 Console.WriteLine("Yes, sum = {0}" , leftSum);
  47.             }
  48.             else
  49.             {
  50.                 Console.WriteLine("No, diff = {0}" , Math.Abs(leftSum - rightSum));
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement