Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _03.PhoneShop
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- List<string> phones = Console.ReadLine().Split(", ").ToList();
- string input;
- while ( (input = Console.ReadLine()) != "End" )
- {
- string[] command = input.Split();
- if (command[0] == "Add")
- {
- if ( !(phones.Contains(command[2])) )
- {
- phones.Add(command[2]);
- }
- }
- else if (command[0] == "Remove")
- {
- if (phones.Contains(command[2]))
- {
- phones.Remove(command[2]);
- }
- }
- else if ( (command[0] == "Bonus") && (command[1] == "phone") )
- {
- string newPhoneArray = command[3];
- int indexOfTheDivider = newPhoneArray.IndexOf(":");
- string oldPhone = "";
- for (int i = 0; i < indexOfTheDivider; i++)
- {
- oldPhone += newPhoneArray[i];
- }
- string newPhone = "";
- for (int i = indexOfTheDivider + 1; i < newPhoneArray.Length; i++)
- {
- newPhone += newPhoneArray[i];
- }
- if (phones.Contains(oldPhone))
- {
- int indexOfTheOldPhone = phones.IndexOf(oldPhone) + 1;
- phones.Insert(indexOfTheOldPhone, newPhone);
- }
- }
- else if (command[0] == "Last")
- {
- if (phones.Contains(command[2]))
- {
- int indexOfThePhone = phones.IndexOf(command[2]);
- string phoneWtihChangePosition = phones[indexOfThePhone];
- phones.Remove(command[2]);
- phones.Add(phoneWtihChangePosition);
- }
- }
- }
- Console.WriteLine(string.Join(", ", phones));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement