Hello, I’m working on this task:
To open the cage and save the captive, you need to enter the code phrase in a simplified Pig Latin language. Infinity is working hard to find the code phrase; your job is to write a converter for English to Pig Latin. In the Main method, read a string from the console, treating a space as a word separator. Output this string in simplified Pig Latin. Ignore double spaces. The code phrase contains only lower case letters.
English is translated to a simplified Pig Latin by taking the first letter of every word, moving it to the end of the word, and adding “ay”. For example:
>the quick brown fox
hetay uickqay rownbay oxfay
Here is my code:
namespace Null
{
class PigLatin
{
public static void Main()
{
string codePhrase = Console.ReadLine();
string[] words = codePhrase.Split(' ');
foreach (string word in words)
{
List<char> letters = new(word);
char firstLetter = letters[0];
letters.RemoveAt(0);
letters.Add(firstLetter);
letters.Add('a');
letters.Add('y');
string newWord = string.Join("", letters);
Console.Write(newWord + " ");
}
}
}
}
Can anyone please help me to solve it?