Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _11._The_Party_Reservation_Filter_Module
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> guestList = Console.ReadLine().Split().ToList();
- HashSet<string> actions = new HashSet<string>();
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "Print")
- {
- break;
- }
- string[] tokens = command.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- string action = tokens[0];
- string condition = tokens[1];
- string filter = tokens[2];
- switch (action)
- {
- case "Add filter":
- actions.Add(new string($"{condition};{filter}"));
- break;
- case "Remove filter":
- actions.Remove(new string($"{condition};{filter}"));
- break;
- default:
- break;
- }
- }
- foreach (var action in actions)
- {
- string[] tokens = action.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- string condition = tokens[0];
- string filter = tokens[1];
- switch (condition)
- {
- case "Starts with":
- case "Ends with":
- guestList.RemoveAll(x => StartsOrEnds(x, filter, condition)); break;
- case "Lenght": guestList.RemoveAll(x => x.Length == int.Parse(filter)); break;
- case "Contains": guestList.RemoveAll(x => x.Contains(filter)); break;
- default:
- break;
- }
- }
- Console.WriteLine(string.Join(" ", guestList));
- }
- static bool StartsOrEnds(string word, string value, string condition)
- {
- if (condition == "Starts with")
- {
- for (int i = 0; i < Math.Min(word.Length, value.Length); i++)
- {
- if (word[i] != value[i])
- {
- return false;
- }
- }
- return true;
- }
- else
- {
- char[] wordReversed = word.ToCharArray().Reverse().ToArray();
- char[] valueReversed = value.ToCharArray().Reverse().ToArray();
- return StartsOrEnds(new string(wordReversed), new string(valueReversed), "Starts with");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement