petyaminkova91

Untitled

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