Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace _02ChatLogger
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> msgs = new List<string>();
- while (true)
- {
- string command = Console.ReadLine();
- if (command== "end")
- {
- break;
- }
- string[] tokens = command.Split();
- string action = tokens[0];
- if (action == "Chat")
- {
- string currMsg = tokens[1];
- msgs.Add(currMsg);
- }
- else if (action == "Delete")
- {
- string currMsg = tokens[1];
- if (msgs.Contains(currMsg))
- {
- msgs.Remove(currMsg);
- }
- }
- else if (action == "Edit")
- {
- string msgToEdit = tokens[1];
- string editedMsg = tokens[2];
- if (msgs.Contains(msgToEdit))
- {
- int index = msgs.IndexOf(msgToEdit);
- msgs.Insert(index, editedMsg);
- msgs.RemoveAt(index + 1);
- }
- }
- else if (action == "Pin")
- {
- string currMsg = tokens[1];
- if (msgs.Contains(currMsg))
- {
- int index = msgs.IndexOf(currMsg);
- msgs.Add(currMsg);
- msgs.RemoveAt(index);
- }
- }
- else if (action == "Spam")
- {
- List<string> spamMsgs = new List<string>();
- for (int i = 1; i < tokens.Length; i++)
- {
- spamMsgs.Add(tokens[i]);
- }
- msgs.AddRange(spamMsgs);
- }
- }
- Console.WriteLine(string.Join(Environment.NewLine,msgs));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment