Advertisement
skipter

Tear List in Half and tear num in two

Jul 11th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace _5.Tear_List_in_Half
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             List<int> listForSeparation = Console.ReadLine()
  11.                 .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  12.                 .Select(int.Parse)
  13.                 .ToList();
  14.  
  15.             TearListInHalf(listForSeparation);
  16.         }
  17.         private static void TearListInHalf (List<int> list)
  18.         {
  19.             var firstList = new List<int>();
  20.             var secondList = new List<int>();
  21.  
  22.             for (int cnt = 0; cnt < list.Count; cnt++)
  23.             {
  24.                 if (cnt < list.Count / 2)
  25.                 {
  26.                     firstList.Add(list[cnt]);
  27.                 } else
  28.                 {
  29.                     secondList.Add(list[cnt]);
  30.                 }
  31.             }
  32.             Output(firstList, secondList);
  33.         }
  34.  
  35.         private static void Output(List<int> firstList, List<int> secondList)
  36.         {
  37.             var resultList = new List<int>();
  38.  
  39.             for (int cnt = 0; cnt < firstList.Count; cnt++)
  40.             {
  41.                 int firstDigit = secondList[cnt] / 10;
  42.                 int secondDigit = secondList[cnt] % 10;
  43.                 resultList.Add(firstDigit);
  44.                 resultList.Add(firstList[cnt]);
  45.                 resultList.Add(secondDigit);
  46.             }
  47.             Console.WriteLine(string.Join(" ", resultList));
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement