Advertisement
grubcho

Tear list in a half - GetRange, RemoveRange - Lists

Jun 24th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 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. //You will receive a list of integers on the first input line (space-separated). Your task is to separate the list into two parts and //perform the following operations
  7. namespace Tear_list_in_half
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> input = Console.ReadLine().Split().Select(int.Parse).ToList();
  14.             List<int> tempList = input.GetRange(input.Count / 2, input.Count / 2);
  15.             input.RemoveRange(input.Count / 2, input.Count / 2);
  16.             for (int i = 0; i < tempList.Count; i++)
  17.             {
  18.                 int firstDigit = tempList[i] / 10;
  19.                 input.Insert(i*3, firstDigit);
  20.                 int secondDigit = tempList[i] % 10;
  21.                 input.Insert(i * 3 + 2, secondDigit);
  22.             }
  23.             Console.WriteLine(string.Join(" ", input));
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement