bullit3189

Quests Journal - TF-MidExam 4Nov18

Jan 26th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _03QuestsJournal
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> journal = Console.ReadLine().Split(", ").ToList();
  12.  
  13. while (true)
  14. {
  15. string command = Console.ReadLine();
  16.  
  17. if (command=="Retire!")
  18. {
  19. break;
  20. }
  21.  
  22. string[] tokens = command.Split(new string[] { " - ", ":"}, StringSplitOptions.RemoveEmptyEntries);
  23.  
  24. string action = tokens[0];
  25.  
  26. if (action == "Start")
  27. {
  28. string quest = tokens[1];
  29.  
  30. if (journal.Contains(quest))
  31. {
  32. continue;
  33. }
  34.  
  35. journal.Add(quest);
  36. }
  37. else if (action=="Complete")
  38. {
  39. string quest = tokens[1];
  40.  
  41. if (journal.Contains(quest))
  42. {
  43. journal.Remove(quest);
  44. }
  45. }
  46. else if (action == "Side Quest")
  47. {
  48. string quest = tokens[1];
  49. string sideQuest = tokens[2];
  50.  
  51. if (journal.Contains(quest))
  52. {
  53. int index = journal.IndexOf(quest);
  54.  
  55. if (journal.Contains(sideQuest)==false)
  56. {
  57. journal.Insert(index + 1, sideQuest);
  58. }
  59. }
  60. }
  61. else if (action == "Renew")
  62. {
  63. string quest = tokens[1];
  64.  
  65. if (journal.Contains(quest))
  66. {
  67. int index = journal.IndexOf(quest);
  68. journal.Add(quest);
  69. journal.RemoveAt(index);
  70. }
  71. }
  72. }
  73.  
  74. Console.WriteLine(string.Join(", ",journal));
  75.  
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment