Advertisement
Guest User

Untitled

a guest
Dec 15th, 2021
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace FoodFinder
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. //vowels - гласни
  13. //consonants - съгласни
  14.  
  15. Queue<char> vowels = new Queue<char>(Console.ReadLine().Split().Select(char.Parse));
  16. Stack<char> consonants = new Stack<char>(Console.ReadLine().Split().Select(char.Parse));
  17.  
  18. string pear = "pear";
  19. string flour = "flour";
  20. string pork = "pork";
  21. string olive = "olive";
  22.  
  23. int pearCount = pear.Count();
  24. int flourCount = flour.Count();
  25. int porkCount = pork.Count();
  26. int oliveCount = olive.Count();
  27.  
  28. int vowelsCount = 0;
  29. int startVowelsCount = vowels.Count;
  30.  
  31.  
  32. while (consonants.Count > 0)
  33. {
  34. char currentVowel = vowels.Dequeue();
  35. char currentConsonant = consonants.Pop();
  36.  
  37. if (vowelsCount < startVowelsCount)
  38. {
  39. if (pear.Contains(currentVowel) && pearCount > 0)
  40. {
  41. pearCount--;
  42.  
  43. }
  44. if (flour.Contains(currentVowel) && flourCount > 0)
  45. {
  46. flourCount--;
  47.  
  48. }
  49. if (pork.Contains(currentVowel) && porkCount > 0)
  50. {
  51. porkCount--;
  52.  
  53. }
  54. if (olive.Contains(currentVowel) && oliveCount > 0)
  55. {
  56. oliveCount--;
  57.  
  58. }
  59. vowelsCount++;
  60. }
  61.  
  62.  
  63. if (pear.Contains(currentConsonant) && pearCount > 0)
  64. {
  65. pearCount--;
  66. }
  67. if (flour.Contains(currentConsonant) && flourCount > 0)
  68. {
  69. flourCount--;
  70. }
  71. if (pork.Contains(currentConsonant) && porkCount > 0)
  72. {
  73. porkCount--;
  74. }
  75. if (olive.Contains(currentConsonant) && oliveCount > 0)
  76. {
  77. oliveCount--;
  78. }
  79.  
  80. vowels.Enqueue(currentVowel);
  81. }
  82.  
  83.  
  84. List<string> wordsFound = new List<string>();
  85.  
  86. if (pearCount == 0)
  87. {
  88. wordsFound.Add(pear);
  89. }
  90. if (flourCount == 0)
  91. {
  92. wordsFound.Add(flour);
  93. }
  94. if (porkCount == 0)
  95. {
  96. wordsFound.Add(pork);
  97. }
  98. if (oliveCount == 0)
  99. {
  100. wordsFound.Add(olive);
  101. }
  102.  
  103. Console.WriteLine($"Words found: {wordsFound.Count}");
  104. foreach (var word in wordsFound)
  105. {
  106. Console.WriteLine(word);
  107. }
  108. }
  109. }
  110. }
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement