Advertisement
YavorGrancharov

Stuck_Zipper_50%

Jun 25th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Stuck_Zipper
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> first = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  12.  
  13.             List<int> second = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  14.  
  15.             List<int> firstIndex = new List<int>();
  16.             List<int> secondIndex = new List<int>();
  17.  
  18.             for (int i = 0; i < first.Count; i++)
  19.             {
  20.                 secondIndex.Add(first[i]);
  21.  
  22.                 for (int j = secondIndex.Count - 1; j >= 0; j--)
  23.                 {
  24.                     if (Math.Abs(first[i]).ToString().Length > Math.Abs(secondIndex[j]).ToString().Length)
  25.                     {
  26.                         secondIndex.Remove(first[i]);
  27.                     }
  28.                     else if (Math.Abs(first[i]).ToString().Length < Math.Abs(secondIndex[j]).ToString().Length)
  29.                     {
  30.                         secondIndex.Remove(secondIndex[j]);
  31.                     }
  32.                 }
  33.             }
  34.  
  35.             for (int i = 0; i < second.Count; i++)
  36.             {
  37.                 firstIndex.Add(second[i]);
  38.  
  39.                 for (int j = firstIndex.Count - 1; j >= 0; j--)
  40.                 {
  41.                     if (Math.Abs(second[i]).ToString().Length > Math.Abs(firstIndex[j]).ToString().Length)
  42.                     {
  43.                         firstIndex.Remove(second[i]);
  44.                     }
  45.                     else if (Math.Abs(second[i]).ToString().Length < Math.Abs(firstIndex[j]).ToString().Length)
  46.                     {
  47.                         firstIndex.Remove(firstIndex[j]);
  48.                     }
  49.                 }
  50.             }
  51.  
  52.             for (int i = 0; i < firstIndex.Count; i++)
  53.             {
  54.                 for (int j = 0; j < secondIndex.Count; j++)
  55.                 {
  56.                     if (Math.Abs(firstIndex[i]).ToString().Length > Math.Abs(secondIndex[i]).ToString().Length)
  57.                     {
  58.                         firstIndex.Remove(firstIndex[i]);
  59.                     }
  60.                     else if (Math.Abs(secondIndex[i]).ToString().Length > Math.Abs(firstIndex[i]).ToString().Length)
  61.                     {
  62.                         secondIndex.Remove(secondIndex[i]);
  63.                     }
  64.                 }
  65.             }
  66.  
  67.             int maxCount = Math.Max(firstIndex.Count, secondIndex.Count);
  68.  
  69.             List<int> zipped = new List<int>();
  70.  
  71.             for (int i = 0; i <= maxCount; i++)
  72.             {
  73.                 if (i < firstIndex.Count)
  74.                 {
  75.                     zipped.Add(firstIndex[i]);
  76.                 }
  77.                 if (i < secondIndex.Count)
  78.                 {
  79.                     zipped.Add(secondIndex[i]);
  80.                 }
  81.             }
  82.             Console.WriteLine(string.Join(" ", zipped));
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement