Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace PhoneShop
- {
- class Program
- {
- static void Main(string[] args)
- {
- var phones = Console.ReadLine().Split(", ").ToList();
- string input;
- while ((input = Console.ReadLine()) != "End")
- {
- var tokens = input.Split(" - ");
- string command = tokens[0], phone = tokens[1];
- if (command == "Add" && !phones.Contains(phone))
- {
- phones.Add(phone);
- }
- else if (command == "Remove" && phones.Contains(phone))
- {
- phones.Remove(phone);
- }
- else if (command == "Bonus phone")
- {
- var models = phone.Split(':');
- string oldPhone = models[0], newPhone = models[1];
- if (phones.Contains(oldPhone))
- {
- phones.Insert(phones.IndexOf(oldPhone) + 1, newPhone);
- }
- }
- else if (command == "Last" && phones.Contains(phone))
- {
- phones.Remove(phone);
- phones.Add(phone);
- }
- }
- Console.WriteLine(String.Join(", ", phones));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement