Advertisement
Iv555

Untitled

Feb 14th, 2022
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5.  
  6. namespace T01FoodFinder
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12.  
  13. Dictionary<string, char[]> allWordsAndLetters = new Dictionary<string, char[]>()
  14. {
  15. {"pear", "pear".ToCharArray()},
  16. {"flour", "flour".ToCharArray()},
  17. {"pork", "pork".ToCharArray()},
  18. {"olive", "olive".ToCharArray()},
  19.  
  20. };
  21.  
  22. char[] vowelsInput = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(char.Parse)
  23. .ToArray();
  24. char[] consonantsInput = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(char.Parse)
  25. .ToArray();
  26. Queue<char> vowels = new Queue<char>(vowelsInput);
  27. Stack<char> consonants = new Stack<char>(consonantsInput);
  28.  
  29. while (consonants.Count > 0)
  30. {
  31. char currVowel = vowels.Dequeue();
  32. char currConsonant = consonants.Pop();
  33.  
  34. allWordsAndLetters["pear"] = allWordsAndLetters["pear"].Where(x => x != currVowel).Where(x => x != currConsonant).ToArray();
  35.  
  36. allWordsAndLetters["flour"] = allWordsAndLetters["flour"].Where(x => x != currVowel).Where(x => x != currConsonant).ToArray();
  37.  
  38. allWordsAndLetters["pork"] = allWordsAndLetters["pork"].Where(x => x != currVowel).Where(x => x != currConsonant).ToArray();
  39.  
  40. allWordsAndLetters["olive"] = allWordsAndLetters["olive"].Where(x => x != currVowel).Where(x => x != currConsonant).ToArray();
  41.  
  42. vowels.Enqueue(currVowel);
  43.  
  44. }
  45.  
  46. int numOfFoundWords = allWordsAndLetters.Count(x => x.Value.Length == 0);
  47.  
  48. Console.WriteLine($"Words found: {numOfFoundWords}");
  49. foreach (KeyValuePair<string, char[]> word in allWordsAndLetters.Where(x => x.Value.Length == 0))
  50. {
  51. Console.WriteLine(word.Key);
  52. }
  53.  
  54. }
  55. }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement