BubaLazi

06StuckZipper

Jul 17th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.62 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 List_Exercises
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             List<int> firstList = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  15.             List<int> secondList = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  16.  
  17.             int minLength = FindMinLengthNumber(firstList, secondList);
  18.  
  19.             List<int> firstFilteredList = new List<int>();
  20.             List<int> secondFilteredList = new List<int>();
  21.  
  22.             for(int i = 0; i < firstList.Count; i++)
  23.             {
  24.                 if(FindNumberLength(firstList[i]) <= minLength)
  25.                 {
  26.                     firstFilteredList.Add(firstList[i]);
  27.                 }
  28.             }
  29.             for (int i = 0; i < secondList.Count; i++)
  30.             {
  31.                 if (FindNumberLength(secondList[i]) <= minLength)
  32.                 {
  33.                     secondFilteredList.Add(secondList[i]);
  34.                 }
  35.             }
  36.             List<int> result = new List<int>();
  37.             for(int i =0; i< Math.Max(firstFilteredList.Count, secondFilteredList.Count);i++)
  38.             {
  39.                 if(i < secondFilteredList.Count)
  40.                 {
  41.                     result.Add(secondFilteredList[i]);
  42.                 }
  43.                 if(i < firstFilteredList.Count)
  44.                 {
  45.                     result.Add(firstFilteredList[i]);
  46.                 }
  47.             }
  48.  
  49.             Console.WriteLine(string.Join(" ", result));
  50.         }
  51.  
  52.         private static int FindMinLengthNumber(List<int> firstList, List<int> secondList)
  53.         {
  54.             int minLength = int.MaxValue;
  55.             for(int i = 0; i < firstList.Count; i++)
  56.             {
  57.                 if(minLength > FindNumberLength(firstList[i]))
  58.                 {
  59.                     minLength = FindNumberLength(firstList[i]);
  60.                 }                
  61.             }
  62.             for (int i = 0; i < secondList.Count; i++)
  63.             {
  64.                 if (minLength > FindNumberLength(secondList[i]))
  65.                 {
  66.                     minLength = FindNumberLength(secondList[i]);
  67.                 }
  68.             }
  69.             return minLength;
  70.  
  71.         }
  72.         private static int FindNumberLength(int number)
  73.         {
  74.             int digitCount = 0;
  75.             number = Math.Abs(number);
  76.             while (number > 0)
  77.             {
  78.                 digitCount++;
  79.                 number /= 10;
  80.             }
  81.             return digitCount;
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment