bullit3189

Chat Logger-TF-MidExam 28Oct18

Jan 27th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _02ChatLogger
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> msgs = new List<string>();
  12.  
  13. while (true)
  14. {
  15. string command = Console.ReadLine();
  16.  
  17. if (command== "end")
  18. {
  19. break;
  20. }
  21.  
  22. string[] tokens = command.Split();
  23.  
  24. string action = tokens[0];
  25.  
  26. if (action == "Chat")
  27. {
  28. string currMsg = tokens[1];
  29. msgs.Add(currMsg);
  30. }
  31. else if (action == "Delete")
  32. {
  33. string currMsg = tokens[1];
  34.  
  35. if (msgs.Contains(currMsg))
  36. {
  37. msgs.Remove(currMsg);
  38. }
  39. }
  40. else if (action == "Edit")
  41. {
  42. string msgToEdit = tokens[1];
  43. string editedMsg = tokens[2];
  44.  
  45. if (msgs.Contains(msgToEdit))
  46. {
  47. int index = msgs.IndexOf(msgToEdit);
  48. msgs.Insert(index, editedMsg);
  49. msgs.RemoveAt(index + 1);
  50. }
  51. }
  52. else if (action == "Pin")
  53. {
  54. string currMsg = tokens[1];
  55.  
  56. if (msgs.Contains(currMsg))
  57. {
  58. int index = msgs.IndexOf(currMsg);
  59. msgs.Add(currMsg);
  60. msgs.RemoveAt(index);
  61. }
  62. }
  63. else if (action == "Spam")
  64. {
  65. List<string> spamMsgs = new List<string>();
  66.  
  67. for (int i = 1; i < tokens.Length; i++)
  68. {
  69. spamMsgs.Add(tokens[i]);
  70. }
  71.  
  72. msgs.AddRange(spamMsgs);
  73. }
  74. }
  75.  
  76. Console.WriteLine(string.Join(Environment.NewLine,msgs));
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment