BorislavBorisov

Task.Joining numbers using Lists<string>

Oct 11th, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. /*20 40 10 10 30 80
  4. 25 20 40 30 10
  5. output 10 20 25 30 40 80*/
  6. class JoinNumbers
  7. {
  8.     static void Main()
  9.     {
  10.         List<string> listOne = new List<string>(Console.ReadLine().Split(' '));
  11.         List<string> listTwo = new List<string>(Console.ReadLine().Split(' '));
  12.  
  13.         List<string> joinNumbers = RemoveOccurNumbers(listOne);
  14.         joinNumbers = UnionAllNumber(joinNumbers,listTwo);
  15.  
  16.         joinNumbers.Sort();
  17.         Console.WriteLine("Now numbers are sorted!");
  18.         foreach (string i in joinNumbers)
  19.         {
  20.             Console.Write(i + " ");
  21.         }
  22.         Console.WriteLine();
  23.     }
  24.     static List<string> UnionAllNumber(List<string> joinNumbers, List<string> listTwo)
  25.     {
  26.         foreach (string i in listTwo)
  27.         {
  28.             if(!joinNumbers.Contains(i))
  29.             {
  30.                 joinNumbers.Add(i);
  31.             }
  32.         }
  33.         return joinNumbers;
  34.     }
  35.     static List<string> RemoveOccurNumbers(List<string> listOne)
  36.     {
  37.         List<string> union = new List<string>();
  38.         foreach (string item in listOne)
  39.         {
  40.             if(union.Contains(item))
  41.             {
  42.                 continue;
  43.             }
  44.             union.Add(item);
  45.         }
  46.         return union;
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment