Advertisement
desislava_topuzakova

Sortings

May 25th, 2022
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CSharpAdvancedMay2022
  4. {
  5. internal class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. //7.
  10. //влогър -> списък с последователи (followers)
  11. //влогър -> списък със следващи (following)
  12.  
  13. Dictionary<string, List<string>> followers = new Dictionary<string, List<string>>();
  14. //спрямо брой на последователи
  15. followers.OrderBy(entry => entry.Value.Count);
  16.  
  17.  
  18. Dictionary<string, List<string>> following = new Dictionary<string, List<string>>();
  19. //сортираме във низходящ ред спрямо брой последованите -> сортираме по име (a - z)
  20. //Иван -> {Петър, Георги, Тишо} 3
  21. //Георги -> {Петър, Иван, Тишо, Мартин} 4
  22. //Мартин -> {Петър, Иван, Тишо} 3
  23. following
  24. .OrderByDescending(entry => entry.Value.Count) //1. Георги 2. Иван 3.Мартин
  25. .ThenBy(entry => entry.Key); //1. Георги 2. Иван 3. Мартин
  26.  
  27. //descending (намаляващ ред): z -> a; 10 -> 0
  28. //ascending (нарастващ ред): a -> z; 0 -> 10
  29.  
  30. //8.
  31. //студент: (курс -> точки)
  32. Dictionary<string, Dictionary<string, int>> students = new Dictionary<string, Dictionary<string, int>> ();
  33.  
  34. //1. име на студентите (нарастващ ред)
  35. //2. намаляващ ред на точките
  36.  
  37. students
  38. .OrderBy(entry => entry.Key); //entry => key: име на студент, value: речник с курсове
  39.  
  40. foreach(var studentEntry in students)
  41. {
  42. //studentEntry: key: име на студент, value: речник с курсове
  43. Dictionary<string, int> courses = studentEntry.Value;
  44. //key: курс, value: точки от курса
  45. courses.OrderByDescending(entry => entry.Value);
  46. }
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. }
  55. }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement