3 thoughts on “数独求解程序 php版

  1. tom882003

    int a[10][10];
    void print(int a[10][10])
    int i,j;
    for (i=1;i<=9;i++) { for (j=1;j<=9;j++) printf("%d",a[i][j]); printf("n"); } printf("n"); } void task(int p,int q) { int i,j,t,m,n; int test(int x,int y,int t,int p,int q); if (a[p][q]==0) for (i=1;i<=9;i++) {t=1; a[p][q]=i; for (j=1;j<=9;j++) if (j!=q&&a[p][j]==i) t=0; if (t) for (j=1;j<=9;j++) if (j!=p&&a[j][q]==i) t=0; if (t) { m=(p-0.1)/3+1; n=(q-0.1)/3+1; t=test(3*m-2,3*n-2,t,p,q); } if (t) { if (p<=9&&q<=8) task(p,q+1); else if(p<=8&&q==9) task(p+1,1); else if(p==9&&q==9) print(a); } a[p][q]=0; } else { if(p<=9&&q<=8) task(p,q+1); else if (p<=8&&q==9) task(p+1,1); else if (p==9&&q==9) print(a); } } int test(int x,int y,int t,int p,int q) { int i,j; for (i=x;i<=x+2;i++) for (j=y;j<=y+2;j++) if ((i!=p||j!=q)&&a[i][j]==a[p][q]) t=0; return (t); } void main() { int i,j; char c='y'; for (i=1;i<=9;i++) for (j=1;j<=9;j++) scanf("%1d",&a[i][j]); print(a); task(1,1); }

  2. Pingback: 数独 php | e路相扶&&hunter_wyg

  3. Pingback: 数独 php | e路相扶&&hunter_wyg

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.