Advertisement
Tervel

Untitled

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