Advertisement
desislava_topuzakova

02

Mar 31st, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Exam
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. List<string> phones = Console.ReadLine().Split(", ").ToList();
  11.  
  12. string command;
  13. while ((command = Console.ReadLine()) != "End")
  14. {
  15. string[] tokens = command.Split(" - ");
  16. string action = tokens[0];
  17. string phone = tokens[1];
  18.  
  19. switch (action)
  20. {
  21. case "Add":
  22. if (!phones.Contains(phone))
  23. {
  24. phones.Add(phone);
  25. }
  26. break;
  27. case "Remove":
  28. phones.Remove(phone);
  29. break;
  30. case "Bonus phone":
  31. string[] bonusTokens = phone.Split(":");
  32. string oldPhone = bonusTokens[0];
  33. string newPhone = bonusTokens[1];
  34. int index = phones.IndexOf(oldPhone);
  35. if (index != -1)
  36. {
  37. phones.Insert(index + 1, newPhone);
  38. }
  39. break;
  40. case "Last":
  41. if (phones.Contains(phone))
  42. {
  43. phones.Remove(phone);
  44. phones.Add(phone);
  45. }
  46. break;
  47. }
  48. }
  49.  
  50. Console.WriteLine(string.Join(", ", phones));
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement