jaredec18

Untitled

Sep 15th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace ConsoleApp1
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. List<int> numbers = new List<int>();
  11. //Reading the line containing comma seperated integers list
  12. var line = Console.ReadLine();
  13. //Splitting to get individual integers
  14. var lineNumbers = line.Split(',');
  15. foreach (var item in lineNumbers)
  16. {
  17. //Adding them to list as list supports Sort() function
  18. numbers.Add(Convert.ToInt32(item));
  19. }
  20. //Sorting the list
  21. numbers.Sort();
  22. //Printing first number
  23. Console.Write(numbers[0]);
  24. numbers.RemoveAt(0);
  25. //All further numbers we are printing preceded with comma
  26. numbers.ForEach(i => Console.Write("," + i));
  27. Console.ReadKey();
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment