Advertisement
Guest User

EqualSumAfterExtraction

a guest
Feb 23rd, 2017
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 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 EqualSumAfterExtraction
  8. {
  9.     public class EqualSumAfterExtraction
  10.     {
  11.         public static void Main()
  12.         {
  13.  
  14.             var firstListOfInt = Console.ReadLine()
  15.                 .Split()
  16.                 .Select(int.Parse)
  17.                 .OrderBy(x => x)
  18.                 .ToList();
  19.  
  20.             var secondListOfInt = Console.ReadLine()
  21.                 .Split()
  22.                 .Select(int.Parse)
  23.                 .OrderBy(x => x)
  24.                 .ToList();
  25.  
  26.             foreach (var item in firstListOfInt)
  27.             {
  28.                 secondListOfInt.Remove(item);
  29.             }
  30.  
  31.             var sumFirts = firstListOfInt.Sum();
  32.             var sumSecond = secondListOfInt.Sum();
  33.             var diff = Math.Abs(sumFirts - sumSecond);
  34.             if (sumFirts == sumSecond)
  35.             {
  36.                 Console.WriteLine($"Yes. Sum: {sumFirts}");
  37.             }
  38.             else
  39.             {
  40.                 Console.WriteLine($"No. Diff: {diff}");
  41.             }
  42.            
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement