dxeqtr

C# FunctionalProgramming 10.PredicateParty

Jun 12th, 2020
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography.X509Certificates;
  5.  
  6. namespace _10.PredictParty
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.  
  13.             List<string> input = Console.ReadLine()
  14.                 .Split()
  15.                 .ToList();
  16.  
  17.             while (true)
  18.             {
  19.                 List<string> command = Console.ReadLine()
  20.                     .Split()
  21.                     .ToList();
  22.  
  23.                 if (command[0] == "Remove")
  24.                 {
  25.                     // EXAMPLE 1
  26.  
  27.                     //input = input.SkipWhile(x =>
  28.                     //{
  29.                     //    if (command[1] == "StartsWith")
  30.                     //        return x.StartsWith(command[2]);
  31.  
  32.                     //    else if (command[1] == "EndsWith")
  33.                     //        return x.EndsWith(command[2]);
  34.  
  35.                     //    else if (command[1] == "Length")
  36.                     //        return x.Length == int.Parse(command[2]);
  37.  
  38.                     //    else return false;
  39.                     //}).ToList();
  40.  
  41.                     // EXAMPLE 2
  42.                     input.RemoveAll(x =>
  43.                     {
  44.                         if (command[1] == "StartsWith")
  45.                             return x.StartsWith(command[2]);
  46.  
  47.                         else if (command[1] == "EndsWith")
  48.                             return x.EndsWith(command[2]);
  49.  
  50.                         else if (command[1] == "Length")
  51.                             return x.Length == int.Parse(command[2]);
  52.  
  53.                         else return false;
  54.                     });
  55.                 }
  56.  
  57.                 if (command[0] == "Double")
  58.                 {
  59.                     if (command[1] == "StartsWith")
  60.                     {
  61.                         List<string> startsWith = input.Where(x => x.StartsWith(command[2])).ToList();
  62.  
  63.                         int index = input.FindIndex(x => x.StartsWith(command[2]));
  64.  
  65.                         input.InsertRange(index, startsWith);
  66.                     }
  67.                     else if (command[1] == "EndsWith")
  68.                     {
  69.                         List<string> endsWith = input.Where(x => x.EndsWith(command[2])).ToList();
  70.  
  71.                         int index = input.FindIndex(x => x.EndsWith(command[2]));
  72.  
  73.                         input.InsertRange(index, endsWith);
  74.  
  75.                     }
  76.                     else if (command[1] == "Length")
  77.                     {
  78.                         List<string> doubleLength = input.Where(x => x.Length == int.Parse(command[2])).ToList();
  79.  
  80.                         int index = input.FindIndex(x => x.Length == int.Parse(command[2]));
  81.  
  82.                         input.InsertRange(index, doubleLength);
  83.                     }
  84.                 }
  85.  
  86.                 else if (command[0] == "Party!")
  87.                     break;
  88.             }
  89.  
  90.             if (input.Count != 0)
  91.             {
  92.                 Console.Write(string.Join(", ", input));
  93.                 Console.WriteLine(" are going to the party!");
  94.             }
  95.  
  96.             else Console.WriteLine("Nobody is going to the party!");
  97.         }
  98.     }
  99. }
Add Comment
Please, Sign In to add comment