Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Friendlist_Maintenance
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. string[] frienlist = Console.ReadLine().Split(", ").ToArray();
  11.  
  12. string input = string.Empty;
  13. int blacklistedCounter = 0;
  14. int errorsCounter = 0;
  15. bool checkBlacklist = false;
  16. bool checkChange = false;
  17.  
  18. while ((input = Console.ReadLine()) != "Report")
  19. {
  20. string[] tokens = input.Split().ToArray();
  21. switch (tokens[0])
  22. {
  23. case "Blacklist":
  24. for (int i = 0; i < frienlist.Length; i++)
  25. {
  26. string current = frienlist[i];
  27. if (frienlist[i] == tokens[1])
  28. {
  29. frienlist[i] = "Blacklisted";
  30. Console.WriteLine($"{current} was blacklisted.");
  31. blacklistedCounter++;
  32. checkBlacklist = true;
  33. break;
  34. }
  35. }
  36. if (checkBlacklist == false)
  37. {
  38. string name = tokens[1];
  39. Console.WriteLine($"{name} was not found.");
  40. }
  41. checkBlacklist = false;
  42. break;
  43. case "Error":
  44. errorsCounter++;
  45. if ((int.Parse(tokens[1])) >= 0 && (int.Parse(tokens[1])) < frienlist.Length)
  46. {
  47. if (frienlist[int.Parse(tokens[1])] != "Blacklisted" && frienlist[int.Parse(tokens[1])] != "Lost")
  48. {
  49. string current = frienlist[(int.Parse(tokens[1]))];
  50. frienlist[(int.Parse(tokens[1]))] = "Lost";
  51. Console.WriteLine($"{current} was lost due to error.");
  52. }
  53. }
  54. break;
  55. case "Change":
  56. for (int i = 0; i < frienlist.Length; i++)
  57. {
  58. string current = frienlist[i];
  59. if (tokens[1] == frienlist[i])
  60. {
  61. frienlist[i] = tokens[2];
  62. Console.WriteLine($"{current} changed his username to {tokens[2]}.");
  63. checkChange = true;
  64. break;
  65. }
  66. }
  67. if (checkChange == false)
  68. {
  69. string name = tokens[1];
  70. Console.WriteLine($"{name} was not found.");
  71. }
  72. checkChange = false;
  73. break;
  74. }
  75. }
  76. Console.WriteLine($"Blacklisted users: {blacklistedCounter}.");
  77. Console.WriteLine($"Errors occurred: {errorsCounter}.");
  78. foreach (var name in frienlist)
  79. {
  80. if (name != "Blacklisted" && name != "Lost")
  81. {
  82. Console.Write($"{name} ");
  83. }
  84. }
  85. }
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement