Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _11.Party_Reservation_Filter_Module
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- public class Program
- {
- private static Dictionary<string, Func<string, string, bool>> allCriterias;
- private static List<KeyValuePair<string, string>> allFilters;
- public static void Main()
- {
- string[] allGuests = SplitStringToArray(Console.ReadLine(), ' ');
- allFilters = new List<KeyValuePair<string, string>>();
- Dictionary<string, Action<KeyValuePair<string, string>>> filterManager = new Dictionary<string, Action<KeyValuePair<string, string>>>
- {
- ["Add filter"] = kvp => allFilters.Add(kvp),
- ["Remove filter"] = kvp => allFilters.Remove(kvp),
- };
- string inputLine;
- while ((inputLine = Console.ReadLine()) != "Print")
- {
- string[] commandArgs = SplitStringToArray(inputLine, ';');
- string filterManageInfo = commandArgs[0];
- string criteria = commandArgs[1];
- string toMatch = commandArgs[2];
- filterManager[filterManageInfo](new KeyValuePair<string, string>(criteria, toMatch));
- }
- allCriterias = new Dictionary<string, Func<string, string, bool>>
- {
- ["Starts with"] = (n, s) => n.StartsWith(s),
- ["Ends with"] = (n, s) => n.EndsWith(s),
- ["Length"] = (n, s) => n.Length == int.Parse(s),
- ["Contains"] = (n, s) => n.Contains(s)
- };
- Console.WriteLine(string.Join(" ", allGuests.Where(g => !GuestIsFiltered(g))));
- }
- private static bool GuestIsFiltered(string guest)
- {
- bool isFiltered = false;
- foreach (KeyValuePair<string, string> kvp in allFilters)
- {
- if (allCriterias[kvp.Key](guest, kvp.Value))
- {
- isFiltered = true;
- break;
- }
- }
- return isFiltered;
- }
- private static string[] SplitStringToArray(string toSplit, char toSplitBy)
- {
- return toSplit.Split(new[] { toSplitBy }, StringSplitOptions.RemoveEmptyEntries);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement