Advertisement
grubcho

Zipper stuck

Jun 25th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 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 stuck_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.             int minValue = Math.Min(Math.Abs(firstList.Min()), Math.Abs(secondList.Min()));
  16.             int minDigitCount = 0;
  17.             while (minValue > 0)
  18.             {
  19.                 minValue = minValue / 10;
  20.                 minDigitCount++;
  21.             }
  22.             for (int i = 0; i < firstList.Count; i++)
  23.             {
  24.                 int digitCount = 0;
  25.                 int currentElement = firstList[i];
  26.                 while (currentElement > 0)
  27.                 {
  28.                     currentElement = currentElement / 10;
  29.                     digitCount++;
  30.                 }
  31.                 if (digitCount > minDigitCount)
  32.                 {
  33.                     firstList.RemoveAt(i);
  34.                     i--;
  35.                 }
  36.             }
  37.             for (int i = 0; i < secondList.Count; i++)
  38.             {
  39.                 int digitCount = 0;
  40.                 int currentElement = secondList[i];
  41.                 while (currentElement > 0)
  42.                 {
  43.                     currentElement = currentElement / 10;
  44.                     digitCount++;
  45.                 }
  46.                 if (digitCount > minDigitCount)
  47.                 {
  48.                     secondList.RemoveAt(i);
  49.                     i--;
  50.                 }
  51.             }
  52.             int count = 1;
  53.             for (int i = 0; i < firstList.Count; i++)
  54.             {
  55.                 if (i + count <= secondList.Count)
  56.                 {
  57.                     secondList.Insert(i + count, firstList[i]);
  58.                     count++;
  59.                 }
  60.                 else if (i + count > secondList.Count)
  61.                 {
  62.                     secondList.Add(firstList[i]);
  63.                    
  64.                 }                
  65.             }
  66.             Console.WriteLine(string.Join(" ", secondList));
  67.         }      
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement