Advertisement
Guest User

Untitled

a guest
Jun 15th, 2017
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _11___The_Party_Reservation_Filter_Module
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             List<string> people = new List<string>(Console.ReadLine().Split(new[] { ' ', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries));
  12.             List<string> filters = new List<string>();
  13.  
  14.             while (true)
  15.             {
  16.                 string input = Console.ReadLine();
  17.  
  18.                 if (input == "Print")
  19.                 {
  20.                     break;
  21.                 }
  22.  
  23.                 var commands = input.Split(new[] { '\n', '\t', ';' }, StringSplitOptions.RemoveEmptyEntries);
  24.  
  25.                 if (commands[0] == "Add filter")
  26.                 {
  27.                     filters.Add(commands[1] + " " + commands[2]);
  28.                 }
  29.                 else if (commands[0] == "Remove filter")
  30.                 {
  31.                     filters.Remove(commands[1] + " " + commands[2]);
  32.                 }
  33.             }
  34.  
  35.             foreach (var filter in filters)
  36.             {
  37.                 string[] commands = filter.Split(' ');
  38.  
  39.                 if (commands[0] == "Starts")
  40.                 {
  41.                     var toRemove = people.Where(p => p.StartsWith(commands[2]));
  42.                     people = people.Except(toRemove).ToList();
  43.                 }
  44.                 else if (commands[0] == "Ends")
  45.                 {
  46.                     var toRemove = people.Where(p => p.EndsWith(commands[2]));
  47.                     people = people.Except(toRemove).ToList();
  48.                 }
  49.                 else if (commands[0] == "Lenght")
  50.                 {
  51.                     var toRemove = people.Where(p => p.Length == int.Parse(commands[1]));
  52.                     people = people.Except(toRemove).ToList();
  53.                 }
  54.                 else if (commands[0] == "Contains")
  55.                 {
  56.                     var toRemove = people.Where(p => p.Contains(commands[1]));
  57.                     people = people.Except(toRemove).ToList();
  58.                 }
  59.             }
  60.  
  61.             Console.WriteLine(string.Join(" ",people));
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement