pascal 变量矩阵定义

来源:百度知道 编辑:UC知道 时间:2024/06/24 13:37:42
目前想编写一个解数独的程序。我想把用户输入的数独题目转化成一个矩阵。这样就可以把各个数字用坐标的方式表达,以确定其是否合法等。也希望大家直接向我提供一下编写解数独的思路。谢谢!

const
st='123456789';
type
xmlnode=array[1..9] of longint;
linenode=array[1..9] of boolean;
squarenode=array[1..3] of linenode;
var
y:char;
sum:integer;
xml:array[1..9] of xmlnode;
linex,liney:array[1..9] of linenode;
square:array[1..3] of squarenode;
procedure init;
var i,j,a,b:integer;temp:char;temp1:integer;
begin
sum:=0;
fillchar(xml,sizeof(xml),0);
fillchar(linex,sizeof(linex),true);
fillchar(liney,sizeof(liney),true);
fillchar(square,sizeof(square),true);
for i:=1 to 9 do
begin
for j:=1 to 9 do
begin
read(temp);
if temp='.' then xml[i][j]:=0
else
begin
temp1:=pos(temp,st);
xml[i][j]:=temp1;
if linex[i][temp1] then linex