gpt4 book ai didi

c# - Pig Latin 控制台

转载 作者:可可西里 更新时间:2023-11-01 15:05:01 25 4
gpt4 key购买 nike

您好,我正在为类里面 Pig Latin,说明首先从单词的前面删除辅音,然后放在单词的后面。然后是字母“ay”。例如,book 变成了 ookbay,strength 变成了 engthstray。我遇到了麻烦,因为它没有发出第一个辅音。

// button, three, nix, eagle, and troubadour
Console.Write("Enter word you want in Pig Latin: ");
string word1 = Console.ReadLine();
string pig = "";
string vowels = "aeiouAEIOU";
string space = " ";
string extra = ""; //extra letters
int pos = 0; //position

foreach (string word in word1.Split())
{
if (pos != 0)
{
pig = pig + space;
}
else
{
pos = 1;
}

vowels = word.Substring(0,1);
extra = word.Substring(1, word.Length - 1);
pig = pig + extra + vowels + "ay";
}

Console.WriteLine(pig.ToString());

例如,如果我做 strength,它会出现 trengthsay 而不是像这个例子

最佳答案

你那里有很多问题。首先,你对问题的定义:

the instructions were first consonant is removed from the front of the word

这正是您所做的。如果您移动第一个辅音优势 确实成为优势。您需要将定义更改为第一个元音之前的所有前导辅音。另外,对于 eagle,您会怎么做?它会变成 eagleay 吗?您的说明没有具体说明如何处理前导元音。

这是另一个问题

vowels = word.Substring(0,1);  // This will overwrite your vowel array with the first letter

暂时不要担心编写真正的代码,先编写一些伪代码来解决您的逻辑问题。 @Chris 关于寻找第一个元音的评论很好。您的伪代码可能类似于:

Check if word begins with consonant
{
If so, look for index of first vowel
Take substring of word up to first vowel.
Append it to end
}
Otherwise
{
Deal with leading vowel
}

关于c# - Pig Latin 控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34645509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com