Advertisement
North_Point

Stuck Zipper

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