Advertisement
Aborigenius

IntegerInsertion

Jun 27th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 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 IntegerInsertion
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> list1 = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  14.  
  15.             string input = Console.ReadLine();
  16.             int x = 0;
  17.  
  18.             while (input != "end")
  19.             {
  20.                 x = int.Parse(input);
  21.                 int firstDigit = GetFirstDigit(x);
  22.                 list1.Insert(firstDigit, x);
  23.                 input = Console.ReadLine();
  24.             }
  25.             for (int i = 0; i < list1.Count; i++)
  26.             {
  27.                 Console.WriteLine(list1[i]);
  28.             }
  29.         }
  30.         public static int GetFirstDigit(int input)
  31.         {
  32.             if (input < 10)
  33.             {
  34.                 return input;
  35.             }
  36.             return GetFirstDigit((input - (input % 10)) / 10);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement