用计算机解题 算法理科,求解数独算法求用计算机可以实现的算法不要人工解题思路 爱问知识人...

[1。。9,1。。9]ofchar;b:array[1。。81,1。。2]ofinteger;i,j,c,s,area,k,l:integer;{c:thenumberofspaces。}x:char;Beginwriteln('Pleaseinputthe9*9square(Youcaninput"*"atanytimeifyouwanttoexit):');fori:=1to9dobeginforj:=1to9dobeginread(a[i,j]);ifa[i,j]=''thenbeginc:=c+1;b[c,1]:=i;b[c,2]:=j;endelseifa[i,j]='*'thenbeginwriteln('Exit。

。。');exitend;end;readln;end;s:=1;Writeln('Pleasestandby。。。

');i:=0;j:=0;Whiles>0dobeginif(i=b[c,1])and(j=b[c,2])thenbeginwriteln;fori:=1to9dobeginforj:=1to9dowrite(a[i,j]);writeln;end;a[i,j]:='';s:=s-1;i:=b[s,1];j:=b[s,2];exit;end;{findasolution}i:=b[s,1];j:=b[s,2];if((i>=1)and(i=1)and(j=4)and(i=1)and(j=7)and(i=1)and(j=1)and(i=4)and(j=4)and(i=4)and(j=7)and(i=4)and(j=1)and(i=7)and(j=4)and(i=7)and(ji)or(l<>j))thencan:=false;fork:=1to9doif((x=a[i,k])and(k<>j))or((x=a[k,j])and(k<>i))thencan:=false;end;ifarea=2thenbeginfork:=4to6doforl:=1to3doif(x=a[k,l])and((k<>i)or(l<>j))thencan:=false;fork:=1to9doif((x=a[i,k])and(k<>j))or((x=a[k,j])and(k<>i))thencan:=falseend;ifarea=3thenbeginfork:=7to9doforl:=1to3doif(x=a[k,l])and((k<>i)or(l<>j))thencan:=false;fork:=1to9doif((x=a[i,k])and(k<>j))or((x=a[k,j])and(k<>i))thencan:=falseend;ifarea=4thenbeginfork:=1to3doforl:=4to6doif(x=a[k,l])and((k<>i)or(l<>j))thencan:=false;fork:=1to9doif((x=a[i,k])and(k<>j))or((x=a[k,j])and(k<>i))thencan:=falseend;ifarea=5thenbeginfork:=4to6doforl:=4to6doif(x=a[k,l])and((k<>i)or(l<>j))thencan:=false;fork:=1to9doif((x=a[i,k])and(k<>j))or((x=a[k,j])and(k<>i))thencan:=falseend;ifarea=6thenbeginfork:=7to9doforl:=4to6doif(x=a[k,l])and((k<>i)or(l<>j))thencan:=false;fork:=1to9doif((x=a[i,k])and(k<>j))or((x=a[k,j])and(k<>i))thencan:=falseend;ifarea=7thenbeginfork:=1to3doforl:=7to9doif(x=a[k,l])and((k<>i)or(l<>j))thencan:=false;fork:=1to9doif((x=a[i,k])and(k<>j))or((x=a[k,j])and(k<>i))thencan:=falseend;ifarea=8thenbeginfork:=4to6doforl:=7to9doif(x=a[k,l])and((k<>i)or(l<>j))thencan:=false;fork:=1to9doif((x=a[i,k])and(k<>j))or((x=a[k,j])and(k<>i))thencan:=falseend;ifarea=9thenbeginfork:=7to9doforl:=7to9doif(x=a[k,l])and((k<>i)or(l<>j))thencan:=false;fork:=1to9doif((x=a[i,k])and(k<>j))or((x=a[k,j])and(k<>i))thencan:=falseend;ifcanthenbreakelseif(x<>'9')thencan:=true;end;ifcanthenbegina[i,j]:=x;s:=s+1;endelsebegina[i,j]:='';s:=s-1;end;end;end。

全部

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值