我尝试解决this问题,但是我的输出似乎有额外的单词,实际上看起来是正确的?
对于以下输入,我得到了这个输出:
qwertyuytresdftyuioknn - >女王,奎恩,问题,quieten,quinin,quintin,quoin
关于问题的答案说正确的单词只是女王和问题但是我没有看到其他单词的任何问题我看作输出的地方问题是什么?
private static string[] words = File.ReadAllLines(path);
static void Main(string[] args)
{
string input = @"qwertyuytresdftyuioknn";
List<string> possibleWords = new List<string>();
for (int i = 0; i < words.Length; i++)
{
if (words[i].Length >= 5 && words[i][0] == input[0] && words[i][words[i].Length - 1] == input[input.Length - 1])
{
possibleWords.Add(words[i]);
}
}
for (int i = 0; i < possibleWords.Count; i++)
{
string tmp = possibleWords[i].Substring(1, possibleWords[i].Length - 2);
bool foundWord = true;
for (int j = 0; j < tmp.Length; j++)
{
if(!input.Contains(tmp[j]))
{
foundWord = false;
break;
}
}
if(foundWord)
{
Console.WriteLine(possibleWords[i]);
}
}
Console.ReadKey();
}