Threed90

FoodFinder

Oct 23rd, 2021
706
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Celebration
  6. {
  7.     public class Program
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             Queue<string> vowels = new Queue<string>(Console.ReadLine().Split());
  12.             Stack<string> consonants = new Stack<string>(Console.ReadLine().Split());
  13.  
  14.             Dictionary<string, string> words = new Dictionary<string, string>()
  15.             {
  16.                 { "pear", "pear" },
  17.                 { "flour", "flour" },
  18.                 { "pork", "pork" },
  19.                 { "olive", "olive"}
  20.             };
  21.  
  22.             while (vowels.Count > 0 && consonants.Count > 0)
  23.             {
  24.                 string vowelsLetter = vowels.Dequeue();
  25.                 string conLetter = consonants.Pop();
  26.  
  27.                 RemoveLetter(words, vowelsLetter, conLetter, "pear");
  28.                 RemoveLetter(words, vowelsLetter, conLetter, "flour");
  29.                 RemoveLetter(words, vowelsLetter, conLetter, "pork");
  30.                 RemoveLetter(words, vowelsLetter, conLetter, "olive");
  31.  
  32.                 vowels.Enqueue(vowelsLetter);
  33.  
  34.             }
  35.  
  36.             Console.WriteLine($"Words found: {words.Where(x => x.Value == string.Empty).Count()} ");
  37.             foreach (var word in words)
  38.             {
  39.                 if(word.Value.Length == 0)
  40.                 {
  41.                     Console.WriteLine(word.Key);
  42.                 }
  43.             }
  44.         }
  45.  
  46.         private static void RemoveLetter(Dictionary<string, string> words, string vowelsLetter, string conLetter, string v)
  47.         {
  48.             if (words[v].Contains(vowelsLetter))
  49.             {
  50.                 words[v] = words[v].Replace(vowelsLetter, string.Empty);
  51.             }
  52.  
  53.             if (words[v].Contains(conLetter))
  54.             {
  55.                 words[v] = words[v].Replace(conLetter, string.Empty);
  56.             }
  57.         }
  58.     }
  59. }
  60.  
RAW Paste Data