...... perdón si ubique mal mi tema
Código:
#include "stdafx.h"
#include "time.h"
#include "iostream"
#include "stdlib.h"
#include "math.h"
using namespace std;
int a[9][9], b[9][9];
bool Verif_cuadros(int grupo){
int posic, i;
bool acepto;
acepto= true;
for (posic=1; posic<10; posic++) {
for (i=1; i<posic; i++) {
if (b[grupo][posic]==b[grupo][i]) {
acepto=false;
goto sali;
}
}
}
sali: return acepto;
}
void Mezclar(){
int restoX, restoY;
int subir, t, x, y;
float X, Y;
int grupo, posic;
bool repet=false, acepta;
srand((unsigned)time(NULL));
//recorre la matriz a partir del 1
for (y=1; y<10; y++) {
for (x=1; x<10; x++) {
a[y][x]= (rand()%9) + 1;
//busca repetidos antes de x
for (t=1; t<x; t++) {
if (a[y][x]==a[y][t]) repet=true;
}
//busca repetidos antes de y
if (repet==false) {
for (t=1; t<y; t++) {
if (a[y][x]==a[t][x]) repet=true;
}
}
//si se repite
if (repet==true){
repet=false;
if (subir> 20){
subir= 0;
x= 0;
}
else {
subir++;
x--;
}
}
// si no se repite
else {
//busca multiplos de 3
/*
1 : 1
2 : 2
3 : 0
4 : 1
5 : 2
6 : 0
7 : 1
8 : 2
9 : 0
Ceil de 1 sobre 3 : 1
Ceil de 2 sobre 3 : 1
Ceil de 3 sobre 3 : 1
Ceil de 4 sobre 3 : 2
Ceil de 5 sobre 3 : 2
Ceil de 6 sobre 3 : 2
Ceil de 7 sobre 3 : 3
Ceil de 8 sobre 3 : 3
Ceil de 9 sobre 3 : 3
*/
restoY= y % 3;
restoX= x % 3;
if (restoX==0) restoX=3;
if (restoY==0) restoY=3;
Y= y; X= x;
posic= 3*(restoY-1) + restoX;
grupo= 3*(ceil(Y/3)-1) + ceil(X/3);
b[grupo][posic]= a[y][x];
subir= 0;
}
}
if ((y%3)==0) {
for (grupo=y-2; grupo<=y; grupo++){
acepta= Verif_cuadros(grupo);
if (acepta==false) {
y= y-3;
goto sali;
}
}
}
sali:;
}
}
void Imprimir(){
int y, x;
for (y=1; y<10; y++) {
for (x=1; x<10; x++) {
cout << a[y][x] << " ";
}
cout << endl;
}
cout<<endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
Mezclar();
Imprimir();
system("pause");
return 0;
}



Este tema le ha gustado a 1 personas