Advertisement
bullit3189

Santa's List - TF-MidExam 18Dec18

Jan 26th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _02Santa_sList
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> noisyKids = Console.ReadLine().Split('&').ToList();
  12.  
  13. while (true)
  14. {
  15. string command = Console.ReadLine();
  16.  
  17. if (command == "Finished!")
  18. {
  19. break;
  20. }
  21.  
  22. string[] tokens = command.Split();
  23. string action = tokens[0];
  24.  
  25. if (action=="Bad")
  26. {
  27. string kidName = tokens[1];
  28.  
  29. if (noisyKids.Contains(kidName)==false)
  30. {
  31. noisyKids.Insert(0, kidName);
  32. }
  33. }
  34. else if (action=="Good")
  35. {
  36. string kidName = tokens[1];
  37.  
  38. if (noisyKids.Contains(kidName))
  39. {
  40. noisyKids.Remove(kidName);
  41. }
  42. }
  43. else if (action == "Rename")
  44. {
  45. string oldName = tokens[1];
  46. string newName = tokens[2];
  47.  
  48. if (noisyKids.Contains(oldName))
  49. {
  50. int index = noisyKids.IndexOf(oldName);
  51. noisyKids.Insert(index, newName);
  52. noisyKids.Remove(oldName);
  53. }
  54. }
  55. else if (action == "Rearrange")
  56. {
  57. string kidName = tokens[1];
  58.  
  59. if (noisyKids.Contains(kidName))
  60. {
  61. noisyKids.Remove(kidName);
  62. noisyKids.Add(kidName);
  63. }
  64. }
  65. }
  66.  
  67. Console.WriteLine(string.Join(", ",noisyKids));
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement