Advertisement
Guest User

Untitled

a guest
Dec 15th, 2021
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.76 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.             string pear1 = "pear";
  24.             string flour1 = "flour";
  25.             string pork1 = "pork";
  26.             string olive1 = "olive";
  27.  
  28.             int pearCount = pear.Count();
  29.             int flourCount = flour.Count();
  30.             int porkCount = pork.Count();
  31.             int oliveCount = olive.Count();
  32.  
  33.             int vowelsCount = 0;
  34.             int startVowelsCount = vowels.Count;
  35.  
  36.  
  37.             while (consonants.Count > 0)
  38.             {
  39.                 char currentVowel = vowels.Dequeue();
  40.                 char currentConsonant = consonants.Pop();
  41.  
  42.                 if (vowelsCount < startVowelsCount)
  43.                 {
  44.                     if (pear.Contains(currentVowel) && pearCount > 0)
  45.                     {
  46.                         pear = pear.Replace(currentVowel.ToString(), "");
  47.                         pearCount--;
  48.  
  49.                     }
  50.                     if (flour.Contains(currentVowel) && flourCount > 0)
  51.                     {
  52.                         flour = flour.Replace(currentVowel.ToString(), "");
  53.                         flourCount--;
  54.  
  55.                     }
  56.                     if (pork.Contains(currentVowel) && porkCount > 0)
  57.                     {
  58.                         pork = pork.Replace(currentVowel.ToString(), "");
  59.                         porkCount--;
  60.  
  61.                     }
  62.                     if (olive.Contains(currentVowel) && oliveCount > 0)
  63.                     {
  64.                         olive = olive.Replace(currentVowel.ToString(), "");
  65.                         oliveCount--;
  66.  
  67.                     }
  68.                     vowelsCount++;
  69.                 }
  70.  
  71.  
  72.                 if (pear.Contains(currentConsonant))
  73.                 {
  74.                     pear = pear.Replace(currentConsonant.ToString(), "");
  75.                     pearCount--;
  76.                 }
  77.                 if (flour.Contains(currentConsonant))
  78.                 {
  79.                     flour = flour.Replace(currentConsonant.ToString(), "");
  80.                     flourCount--;
  81.                 }
  82.                 if (pork.Contains(currentConsonant))
  83.                 {
  84.                     pork = pork.Replace(currentConsonant.ToString(), "");
  85.                     porkCount--;
  86.                 }
  87.                 if (olive.Contains(currentConsonant))
  88.                 {
  89.                     olive = olive.Replace(currentConsonant.ToString(), "");
  90.                     oliveCount--;
  91.                 }
  92.  
  93.                 vowels.Enqueue(currentVowel);
  94.             }
  95.  
  96.             List<string> wordsFound = new List<string>();
  97.  
  98.             if (pear.Length == 0)
  99.             {
  100.                 wordsFound.Add(pear1);
  101.             }
  102.             if (flour.Length == 0)
  103.             {
  104.                 wordsFound.Add(flour1);
  105.             }
  106.             if (pork.Length == 0)
  107.             {
  108.                 wordsFound.Add(pork1);
  109.             }
  110.             if (olive.Length == 0)
  111.             {
  112.                 wordsFound.Add(olive1);
  113.             }
  114.  
  115.             Console.WriteLine($"Words found: {wordsFound.Count}");
  116.             foreach (var word in wordsFound)
  117.             {
  118.                 Console.WriteLine(word);
  119.             }
  120.         }
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement