Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace PredicateParty
- {
- class Program
- {
- static void Main()
- {
- List<string> namesParty = Console.ReadLine()
- .Split()
- .ToList();
- CheckRequirements(namesParty);
- PrintComingToParty(namesParty);
- }
- static void CheckRequirements(List<string> partyPeople)
- {
- while (true)
- {
- string[] command = Console.ReadLine()
- .Split(new char[] { ' ', '\n', '\r', '\t' }, StringSplitOptions.RemoveEmptyEntries);
- if (command[0] == "Party!")
- {
- break;
- }
- switch (command[1])
- {
- case "StartsWith": //certain string
- TakeActions(command[0], partyPeople, n => n.StartsWith(command[2]));
- break;
- case "EndsWith":
- TakeActions(command[0], partyPeople, n => n.EndsWith(command[2]));
- break;
- case "Length": //check name length
- TakeActions(command[0], partyPeople, l => l.Length == int.Parse(command[2]));
- break;
- default:
- break;
- }
- }
- }
- static void TakeActions(string command, List<string> partyPeople, Func<string, bool> condition)
- {
- //if counting from 0, gives Memory Limit problem in Judge
- for (int i = partyPeople.Count - 1; i >= 0; i--)
- {
- if (condition(partyPeople[i]))
- {
- switch (command)
- {
- case "Remove":
- partyPeople.RemoveAt(i);
- break;
- case "Double":
- partyPeople.Add(partyPeople[i]);
- break;
- }
- }
- }
- }
- static void PrintComingToParty(List<string> partyPeople)
- {
- if(partyPeople.Any())
- {
- Console.WriteLine(string.Join(", ", partyPeople) + " are going to the party!");
- }
- else
- {
- Console.WriteLine("Nobody is going to the party!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment