Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Exam
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> phones = Console.ReadLine().Split(", ").ToList();
- string command;
- while ((command = Console.ReadLine()) != "End")
- {
- string[] tokens = command.Split(" - ");
- string action = tokens[0];
- string phone = tokens[1];
- switch (action)
- {
- case "Add":
- if (!phones.Contains(phone))
- {
- phones.Add(phone);
- }
- break;
- case "Remove":
- phones.Remove(phone);
- break;
- case "Bonus phone":
- string[] bonusTokens = phone.Split(":");
- string oldPhone = bonusTokens[0];
- string newPhone = bonusTokens[1];
- int index = phones.IndexOf(oldPhone);
- if (index != -1)
- {
- phones.Insert(index + 1, newPhone);
- }
- break;
- case "Last":
- if (phones.Contains(phone))
- {
- phones.Remove(phone);
- phones.Add(phone);
- }
- break;
- }
- }
- Console.WriteLine(string.Join(", ", phones));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement