CSharp · Console
using System;
using System.Linq;
public class Program
{
public static void Main()
{
Console.WriteLine(Flippedy("cat and mice"));
Console.WriteLine(Flippedy("banana healthy"));
}
static string Flippedy(string s)
{
var words = s.Split(' ');
var wordOneVowelCount = VowelCount(words[0]);
for (var i = 1; i < words.Length; i++)
{
if (VowelCount(words[i]) == wordOneVowelCount)
words[i] = new string([.. words[i].Reverse()]);
}
return string.Join(' ', words);
}
static int VowelCount(string s)
{
var vowels = new char[] {'a', 'e', 'i', 'o', 'u'};
var count = 0;
for (var i = 0; i < s.Length; i++)
{
if (vowels.Contains(s[i]))
count++;
}
return count;
}
}