Advertisement
azaria77

Followers-with class-help

Mar 29th, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03.Followers_s_methods
  6. {
  7. class Follower
  8. {
  9. public Follower(string name, int likes, int comments)
  10. {
  11. Name = name;
  12. Likes = likes;
  13. Comments = comments;
  14. }
  15.  
  16. public string Name { get; set; }
  17. public int Likes { get; set; }
  18. public int Comments { get; set; }
  19.  
  20. public override string ToString()
  21. {
  22. return $"{this.Name}: {this.Likes + this.Comments}";
  23. }
  24. }
  25. class Program
  26. {
  27. static void Main(string[] args)
  28. {
  29. List<Follower> followers = new List<Follower>();
  30. string input;
  31. while ((input = Console.ReadLine()) != "Log out")
  32. {
  33. string[] splitted = input.Split(":");
  34. string command = splitted[0];
  35. string user = splitted[1];
  36.  
  37.  
  38. switch (command)
  39. {
  40. case "New follower":
  41. if (followers.Find(x => x.Name == user) == null)
  42. {
  43. Follower follower = new Follower(user, +0, +0);
  44. followers.Add(follower);
  45. }
  46. break;
  47. case "Like":
  48. int likes = int.Parse(splitted[2]);
  49. if (followers.Find(x => x.Name == user) == null)
  50. {
  51. Follower follower = new Follower(user, +likes, +0);
  52. followers.Add(follower);
  53. }
  54. else
  55. {
  56. followers.Find(x => x.Name == user).Likes += likes;
  57. }
  58. break;
  59. case "Comment":
  60. if (followers.Find(x => x.Name == user) == null)
  61. {
  62. Follower follower = new Follower(user, +0, +1);
  63. followers.Add(follower);
  64. }
  65. else
  66. {
  67. followers.Find(x => x.Name == user).Comments += 1;
  68. }
  69. break;
  70. case "Blocked":
  71. if (!(followers.Find(x => x.Name == user) == null))
  72. {
  73.  
  74. followers = followers.FindAll(x => x.Name != user);
  75. }
  76. break;
  77. }
  78. }
  79. Console.WriteLine($"{followers.Count} followers");
  80. List<Follower> sorted = followers.OrderByDescending(l => l.Likes).ThenBy(n => n.Name).ToList();
  81. Console.WriteLine(String.Join("\n", sorted));
  82.  
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement