Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- //You will be given two integer lists on the first two lines (space-separated). Remove the elements in the first list from the elements //in the second list. If an element from the first list occurs more than once in the second list, remove all occurrences.
- //After you remove the elements, check the sum of both lists. If the sum of both of them is equal, print βYes. Sum: {sum}β. If not //print the absolute difference between the two lists in the format βNo. Diff: {sum}β.
- namespace Equal_Sum_After_Extraction
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> firstList = Console.ReadLine().Split().Select(int.Parse).ToList();
- List<int> secondList = Console.ReadLine().Split().Select(int.Parse).ToList();
- for (int i = 0; i < firstList.Count; i++)
- {
- for (int j = 0; j < secondList.Count; j++)
- {
- if (firstList[i] == secondList[j])
- {
- secondList.RemoveAll(a => a == firstList[i]);
- }
- }
- }
- int sumOfFirstList = firstList.Sum();
- int sumOfSecondList = secondList.Sum();
- if (sumOfFirstList == sumOfSecondList)
- {
- Console.WriteLine($"Yes. Sum: {sumOfSecondList}");
- }
- else
- {
- Console.WriteLine("No. Diff: {0}", Math.Abs(sumOfFirstList - sumOfSecondList));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement