Home > Back-end >  How to only get a result
How to only get a result

Time:10-04

# include & lt; stdio.h>
# include & lt; Stdlib. H>

Int count=0;
Void print (int a [30] [6])
{
count++;
Printf (" case: % d: \ n ", count);
for(int i=0; i<30; I++)
for(int j=0; j<6; J++)
{
Printf (" % d ", a [I] [j]);
J==5? Printf (" % d \ n ", I) : 0;
}

}
//determine whether the line, I can be the first j column is set to k
Int test (int a [30] [6], int, int j, int k)
{
Int p, q;
P=0;
While (p<6) {
If (a [I] [p]==k) return 0;
The else + + p;
}

Int num1=1, col=0;
While (colFor (q=0; Q
If ((a [q] [col]==a [I] [col] & amp; & A [q] [j]==k) | | (a [q] [col]==k& & A [q] [j]==a [I] [col]))
+ + num1;
}
If (num1 & gt; 2) return 0;
The else {
Col++;
Num1=1;
}
}
return 1;
}

Void SD (int a [30] [6], int n)//solving
{
If (n==180) {
Print (a);
return ;
}
int i,j;
Int b [30] [6].
for(i=0; i<30; I++)
for(j=0; j<6; J++)
B [j]=[I] a [I] [j];//try using b
I=n/6, j=n % 6;//list
If (a [I] [j].=0) {
SD (b, n + 1);
A [I] [j]=0;
}//if the position fixed

The else
{
Int k;//try several
For (k=1; k<=6; K++) {
If (test (b, I, j, k))//can
{
B [I] [j]=k;
SD (b, n + 1);
B [I] [j]=0;
}
If (n==180)
break;
}

}

}
Int main ()
{
Int a [30] [6].
Printf (" please enter the original data, replace with 0, no data \ n ");
for(int i=0; i<30; I++)
for(int j=0; j<6; J++)
The scanf (" % d ", & amp; A [I] [j]);
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n \ n ");
SD (a, 0);
If (count==0) {
Printf (" this array with no solution!" );
Return 0;
}
}
  • Related