Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace PartyReservationFilterModule
- {
- class Program
- {
- static void Main()
- {
- List<string> invitations = Console.ReadLine()
- .Split(new char[] { ' ', '\n', '\r', '\t' }, StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- List<string> filters = new List<string>();
- AddActions(filters);
- RemoveFilterBased(invitations, filters);
- if (invitations.Count > 0)
- Console.WriteLine(string.Join(" ", invitations));
- }
- static void AddActions(List<string> filters)
- {
- while (true)
- {
- string[] command = Console.ReadLine().Split(";");
- if (command[0] == "Print")
- {
- break;
- }
- switch (command[0])
- {
- case "Add filter":
- filters.Add(CheckConditions(command));
- break;
- case "Remove filter":
- filters.Remove(CheckConditions(command));
- break;
- }
- }
- }
- static string CheckConditions(string[] command)
- {
- string condition = string.Empty;
- switch (command[1])
- {
- case "Starts with":
- condition = "Starts " + command[2];
- break;
- case "Ends with":
- condition = "Ends " + command[2];
- break;
- case "Length":
- condition = "Length " + command[2];
- break;
- case "Contains":
- condition = "Contains " + command[2];
- break;
- }
- return condition;
- }
- static void RemoveFilterBased(List<string> invitations, List<string> filters)
- {
- Func<string, string, bool> startsWith = (a, b) => a.StartsWith(b);
- Func<string, string, bool> endsWith = (a, b) => a.EndsWith(b);
- Func<string, string, bool> contains = (a, b) => a.Contains(b);
- Func<string, int, bool> lengthFilter = (a, b) => a.Length >= b;
- while (filters.Count > 0)
- {
- string[] filter = filters.Last().Split();
- filters.RemoveAt(filters.Count - 1);
- switch (filter[0])
- {
- case "Starts":
- invitations.RemoveAll(i => startsWith(i, filter[1]));
- break;
- case "Ends":
- invitations.RemoveAll(i => endsWith(i, filter[1]));
- break;
- case "Length":
- invitations.RemoveAll(i => lengthFilter(i, int.Parse(filter[1])));
- break;
- case "Contains":
- invitations.RemoveAll(i => contains(i, filter[1]));
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement