Thursday, 15 June 2017

Find All vowels in string using C#

public static void Main()
        {
            int size = int.Parse(ReadLine());
            var inputValue = "";
            for (int i = 0; i < size; i++)
            {
                inputValue += Console.ReadLine();
            }
            var vowels = new HashSet<char> { 'a', 'e', 'i', 'o', 'u' };
            bool findVowels = false;
            var findCharGroup = inputValue.GroupBy(x => x).Select(x => new
            {
                key = x.Key,
                Count = x.Count()
            }).ToDictionary(t => t.key, t => t.Count);

            foreach (var itemVowels in vowels)
            {

                if (findCharGroup.ContainsKey(itemVowels))
                {
                    findVowels = true;
                }
                else
                {
                    findVowels = false;
                    break;
                }

            }
            WriteLine(findVowels ? "YES" : "NO");
            ReadLine();
        }

No comments:

Post a Comment