这里我的代码列出了一个字符串的所有排列
{
public partial class Form1 : Form
{
private int n;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
string scrambledWord = textBox1.Text;
if (e.KeyCode == Keys.Enter)
{
label4.Text = "";
char[] arr = scrambledWord.ToCharArray();
GetPer(arr);
}
}
public void GetPer(char[] list)
{
int x = list.Length - 1;
GetPer(list, 0, x);
}
private void GetPer(char[] list, int k, int m)
{
if (k == m)
{
Console.WriteLine(list);
var text = new string(list);
label4.Text = label4.Text + text + Environment.NewLine;
}
else
for (int i = k; i <= m; i++)
{
Swap(ref list[k], ref list[i]);
GetPer(list, k + 1, m);
Swap(ref list[k], ref list[i]);
}
}
private void Swap(ref char a, ref char b)
{
if (a == b) return;
var temp = a;
a = b;
b = temp;
}
private void label1_TextChanged(object sender, EventArgs e)
{
label4.Height = label4.Height + 10;
}
}
}
有人知道如何检查是否有任何排列是英语单词,并且代码在Visual Studio上打印英语单词吗?感谢You,You,You,You,You,You,You,You,You,You,You,You,
您将需要在项目中添加一个带有英语词汇表的文本文件(有几个这样的开放源码列表,如果您搜索它们,例如在GitHub上,阅读单词列表并搜索其中的排列)。因为这是大量的单词,如果将单词存储在