Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace FoodFinder
- {
- class Program
- {
- static void Main(string[] args)
- {
- //vowels - гласни
- //consonants - съгласни
- Queue<char> vowels = new Queue<char>(Console.ReadLine().Split().Select(char.Parse));
- Stack<char> consonants = new Stack<char>(Console.ReadLine().Split().Select(char.Parse));
- string pear = "pear";
- string flour = "flour";
- string pork = "pork";
- string olive = "olive";
- int pearCount = pear.Count();
- int flourCount = flour.Count();
- int porkCount = pork.Count();
- int oliveCount = olive.Count();
- int vowelsCount = 0;
- int startVowelsCount = vowels.Count;
- while (consonants.Count > 0)
- {
- char currentVowel = vowels.Dequeue();
- char currentConsonant = consonants.Pop();
- if (vowelsCount < startVowelsCount)
- {
- if (pear.Contains(currentVowel) && pearCount > 0)
- {
- pearCount--;
- }
- if (flour.Contains(currentVowel) && flourCount > 0)
- {
- flourCount--;
- }
- if (pork.Contains(currentVowel) && porkCount > 0)
- {
- porkCount--;
- }
- if (olive.Contains(currentVowel) && oliveCount > 0)
- {
- oliveCount--;
- }
- vowelsCount++;
- }
- if (pear.Contains(currentConsonant) && pearCount > 0)
- {
- pearCount--;
- }
- if (flour.Contains(currentConsonant) && flourCount > 0)
- {
- flourCount--;
- }
- if (pork.Contains(currentConsonant) && porkCount > 0)
- {
- porkCount--;
- }
- if (olive.Contains(currentConsonant) && oliveCount > 0)
- {
- oliveCount--;
- }
- vowels.Enqueue(currentVowel);
- }
- List<string> wordsFound = new List<string>();
- if (pearCount == 0)
- {
- wordsFound.Add(pear);
- }
- if (flourCount == 0)
- {
- wordsFound.Add(flour);
- }
- if (porkCount == 0)
- {
- wordsFound.Add(pork);
- }
- if (oliveCount == 0)
- {
- wordsFound.Add(olive);
- }
- Console.WriteLine($"Words found: {wordsFound.Count}");
- foreach (var word in wordsFound)
- {
- Console.WriteLine(word);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement