这个数独代码出了什么问题? [英] What's wrong with this Sudoku code?
本文介绍了这个数独代码出了什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个数独代码,只是试图检查列是否是核心。我稍后会控制行和方块。虽然对我来说似乎是对的。它不起作用。模拟器冻结了。这是代码:
I''ve written a Sudoku code and just tried to check if columns were corect. I will be controlling rows and squares later. Although it seems right to me. It doesn''t work. the simulator freezes. Here is the code:
TextBox[,] dene = new TextBox[9,9];
Random b = new Random();
int kontrol = 0;
int m=0;
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
dene[i, j] = new TextBox();
dene[i, j].Text = "0" ;
}
}
for (int i = 0; i < 9; i++)
{
for (int j=0;j<9;j++)
{
while (m == 0)
{
int inta = b.Next(1, 10);
for (int k = 0; k < 9; k++)
{
int c = Convert.ToInt32(dene[i, k].Text);
if (inta == c)
{
kontrol++;
}
}
if (kontrol == 9)
{
dene[i, j].Text = inta.ToString();
kontrol = 0;
m = 1;
}
else
{
kontrol = 0;
}
}
m = 0;
}
}
推荐答案
所有文本框都用0初始化。inta
总是大于0.绝不会kontrol ++
发生,kontrol
总是保持0,m也是。而(m == 0)
永远保持真实。
All your textboxes are initialised with ''0''.inta
is always greater than 0. Never willkontrol++
happen,kontrol
always stays 0, and m also.while(m==0)
stays true eternally.
感谢您的解释我'已经找到了solutoin
Thanks to your explanation i''ve found the solutoin with
if (inta != c)
{
kontrol++;
}
Ty非常
Ty very much
这篇关于这个数独代码出了什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文