Advertisement
skipter

List - Equal Sum After Extraction / Delete equal nums

Jul 11th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace EqualSumAfterExtraction
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             List<int> firstList = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  11.             List<int> secondList = Console.ReadLine().Split(' ').Select(int.Parse).ToList();            
  12.             List<int> secondResult = new List<int>();
  13.            
  14.             for (int cnt = 0; cnt < firstList.Count; cnt++)
  15.             {
  16.                 for (int i = 0; i < secondList.Count; i++)
  17.                 {
  18.                     if (firstList[cnt] == secondList[i])
  19.                     {
  20.                        secondList.RemoveAt(i);
  21.                         i--;
  22.                     }
  23.                 }
  24.             }
  25.             long sumList1 = 0L;
  26.             long sumList2 = secondList.Sum();
  27.  
  28.             foreach (int num in firstList)
  29.             {
  30.                 sumList1 += num;
  31.             }
  32.             if (sumList1 == sumList2)
  33.             {
  34.                 Console.WriteLine("Yes. Sum: " + sumList2);
  35.             } else
  36.             {
  37.                 Console.WriteLine("No. Diff: " + Math.Abs(sumList2 - sumList1));
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement