# 不懂快要问。(2)

www.myexceptions.net  网友分享于：2013-02-16  浏览：8次

return 0;

return 1;
}
void output(void)
{
static int n;
int Sudo[9][9]={{0,1,4,0,5,0,0,0,3},{6,0,0,0,0,9,4,2,0},{8,0,0,1,0,0,0,9,0},{0,0,5,0,9,0,0,4,0},{4,0,0,7,0,8,0,5,2},{0,7,0,0,2,0,6,0,0},{0,9,0,0,0,1,0,0,5},{0,2,8,3,0,0,0,0,4},
{5,0,0,0,6,0,7,1,0}};

for (int i = 0; i < 9; i++)
{
int y=i+1;
y=1+2*(y-1);

for (int j = 0; j < 9; j++)
{
int x=j+1;
x=1+3*(x-1);
gotoxy(x,y);
if(sudo[i][j] != Sudo[i][j])
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_RED | FOREGROUND_GREEN);

printf("%d", sudo[i][j]);
}
else
{
gotoxy(x+1,y);
}
S[i][j]=sudo[i][j];

}

}

cout << endl;
}
void Try(const int n)
{

if (n == 81)
{

output();
return;
}

const int i = n / 9, j = n % 9;

if (sudo[i][j] != 0)
{

Try(n + 1);
return;

}

for (int k = 0; k < 9; k++)
{

sudo[i][j]++;
if (isvalid(i,j))
{ Try(n + 1);
}

}
sudo[i][j] = 0;

}

int solver(void)
{

int m_pu[9][9] =
{
{0,1,4,0,5,0,0,0,3},
{6,0,0,0,0,9,4,2,0},
{8,0,0,1,0,0,0,9,0},
{0,0,5,0,9,0,0,4,0},
{4,0,0,7,0,8,0,5,2},
{0,7,0,0,2,0,6,0,0},
{0,9,0,0,0,1,0,0,5},
{0,2,8,3,0,0,0,0,4},
{5,0,0,0,6,0,7,1,0}
};
for (int i = 0; i < 9; ++i)
{
for (int j = 0; j < 9; ++j)
{
sudo[i][j] = m_pu[i][j];
}
}
Try(0);
return 0;
}
int sudocheck()
{
static int c;