MiroslavKisov

PredicateParty

Feb 6th, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.45 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace PredicateParty
  6. {
  7.     public class StartUp
  8.     {
  9.         public static void Main()
  10.         {
  11.             var guests = Console.ReadLine()
  12.                 .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
  13.                 .ToList();
  14.             string command;
  15.             while ((command = Console.ReadLine()) != "Party!")
  16.             {
  17.                 var commandArgs = command
  18.                     .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
  19.                     .ToList();
  20.                 if (command.StartsWith("Double"))
  21.                 {
  22.                     DoubleStr(commandArgs[1], commandArgs[2], guests);
  23.                 }
  24.                 else if (command.StartsWith("Remove"))
  25.                 {
  26.                     RemoveStr(commandArgs[1], commandArgs[2], guests);
  27.                 }
  28.             }
  29.             if (guests.Count > 0)
  30.             {
  31.                 Console.WriteLine(string.Join(", ", guests) + " " + "are going to the party!");
  32.             }
  33.             else
  34.             {
  35.                 Console.WriteLine("Nobody is going to the party!");
  36.             }
  37.         }
  38.  
  39.         private static void RemoveStr(string v1, string v2, List<string> guests)
  40.         {
  41.             if (v1 == "Length")
  42.             {
  43.                 for (int i = 0; i < guests.Count; i++)
  44.                 {
  45.                     if (guests[i].Length == int.Parse(v2))
  46.                     {
  47.                         guests.Remove(guests[i]);
  48.                         i--;
  49.                     }
  50.                 }
  51.             }
  52.             else if (v1 == "StartsWith")
  53.             {
  54.                 for (int i = 0; i < guests.Count; i++)
  55.                 {
  56.                     if (guests[i].StartsWith(v2))
  57.                     {
  58.                         guests.Remove(guests[i]);
  59.                         i--;
  60.                     }
  61.                 }
  62.             }
  63.             else if (v1 == "EndsWith")
  64.             {
  65.                 for (int i = 0; i < guests.Count; i++)
  66.                 {
  67.                     if (guests[i].EndsWith(v2))
  68.                     {
  69.                         guests.Remove(guests[i]);
  70.                         i--;
  71.                     }
  72.                 }
  73.             }
  74.         }
  75.  
  76.  
  77.         private static void DoubleStr(string v1, string v2, List<string> guests)
  78.         {
  79.             if (v1 == "Length")
  80.             {
  81.                 for (int i = 0; i < guests.Count; i++)
  82.                 {
  83.                     if (guests[i].Length == int.Parse(v2))
  84.                     {
  85.                         guests.Insert(i, guests[i]);
  86.                         i++;
  87.                     }
  88.                 }
  89.             }
  90.             else if (v1 == "StartsWith")
  91.             {
  92.                 for (int i = 0; i < guests.Count; i++)
  93.                 {
  94.                     if (guests[i].StartsWith(v2))
  95.                     {
  96.                         guests.Insert(i, guests[i]);
  97.                         i++;
  98.                     }
  99.                 }
  100.             }
  101.             else if (v1 == "EndsWith")
  102.             {
  103.                 for (int i = 0; i < guests.Count; i++)
  104.                 {
  105.                     if (guests[i].EndsWith(v2))
  106.                     {
  107.                         guests.Insert(i, guests[i]);
  108.                         i++;
  109.                     }
  110.                 }
  111.             }
  112.         }
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment