Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. string line = "";
  10. bool first = true;
  11. while ((line = Console.ReadLine()) != "0")
  12. {
  13. int n = int.Parse(line);
  14. if (n >= 1 && n <= 200)
  15. {
  16. List<string> Print = new List<string>();
  17. for (int i = 0; i < n; i++)
  18. {
  19. string input = Console.ReadLine();
  20. if (input.Length <= 2)
  21. input = input + " "; // lägger på 2 mellanslag om stringen är 1 lång
  22. Print.Add(input);
  23. };
  24.  
  25.  
  26.  
  27. var sorted = Print.OrderBy(x => x.Remove(Math.Min(x.Length, 2))); // index 2 = 3:e platsen? 0, 1, 2. Stringen måste väl därför va minst 3? Därav plus 2 mellanslag ovan
  28. if (!first)
  29. {
  30. Console.WriteLine();
  31. }
  32. first = false;
  33. foreach (string name in sorted)
  34. {
  35. Console.WriteLine(name);
  36. }
  37. Console.WriteLine();
  38. }
  39. else
  40. {
  41. break;
  42. }
  43.  
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement