Advertisement
onqkoie

Untitled

Feb 27th, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _02._Friendlist_Maintenance
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. var list = Console.ReadLine().Split(", ").ToList();
  11. int blacklistedNamesCount = 0;
  12. int lostNamesCount = 0;
  13. while (true)
  14. {
  15. string input = Console.ReadLine();
  16.  
  17. if (input == "Report")
  18. {
  19. break;
  20. }
  21.  
  22. var tokens = input.Split();
  23. string command = tokens[0];
  24.  
  25. switch (command)
  26. {
  27. case "Blacklist":
  28. string name = tokens[1];
  29.  
  30. if (list.Contains(name))
  31. {
  32. blacklistedNamesCount++;
  33. Console.WriteLine($"{name} was blacklisted.");
  34. list[list.IndexOf(name)] = "Blacklisted";
  35.  
  36. }
  37. else
  38. {
  39. Console.WriteLine($"{name} was not found.");
  40. }
  41.  
  42. break;
  43.  
  44. case "Error":
  45. int index = int.Parse(tokens[1]);
  46. name = list[index];
  47. if (index < list.Count && index >= 0 && list[index] != "Blacklisted" && list[index] != "Lost")
  48. {
  49. lostNamesCount++;
  50. Console.WriteLine($"{name} was lost due to an error.");
  51. list[index] = "Lost";
  52.  
  53. }
  54. break;
  55.  
  56. case "Change":
  57. index = int.Parse(tokens[1]);
  58. string currentName = list[index];
  59. string newName = tokens[2];
  60. if (index < list.Count && index >= 0)
  61. {
  62. list[index] = newName;
  63. Console.WriteLine($"{currentName} changed his username to {newName}.");
  64. }
  65. break;
  66.  
  67. }
  68. }
  69. Console.WriteLine($"Blacklisted names: {blacklistedNamesCount}");
  70. Console.WriteLine($"Lost names: {lostNamesCount}");
  71. Console.WriteLine(string.Join(" ", list));
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement