#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 9
int isValueInLineOrColumn(int val, int arr[N][N], int line, int column)
{
int i,j;
for (i=0; i < N; i++)
{
if(arr[line][i] == val)
return 1;
if (arr[i][column] == val)
return 1;
}
return 0;
}
int main()
{
int su[N][N];
int i, j;
int cont;
srand( (unsigned)time(NULL
) );//evita que o rand seja gerado pelo tempo
for(i=0; i<N; i++)
{
for(j=0; j<N; j++)
{
if(i==cont || j==cont)
{
//verifica se já existe este valor na linha ou coluna atual.
if(isValueInLineOrColumn(val, su, i, j))
su[i][j]=0;
else
su[i][j]=val;
}
else
{
//usando 0 como identificador de vazio
su[i][j]=0;
}
}
}
for(i=0; i<N; i++)
{
for(j=0; j<N; j++)
{
if(su[i][j]!=0)
else
printf("[ ]");//se for igual a 0 coloca o quadrado vazio. }
}
/*
for(i=1 ; i <= 10 ; i++)
printf("Numero %d: %d\n",i, 1+rand()%9);
*/
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHRpbWUuaD4KCiNkZWZpbmUgTiA5CgppbnQgaXNWYWx1ZUluTGluZU9yQ29sdW1uKGludCB2YWwsIGludCBhcnJbTl1bTl0sIGludCBsaW5lLCBpbnQgY29sdW1uKQp7CiAgICBpbnQgaSxqOwoKICAgIGZvciAoaT0wOyBpIDwgTjsgaSsrKQogICAgewogICAgICAgIGlmKGFycltsaW5lXVtpXSA9PSB2YWwpCiAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgICAgICAKICAgICAgICBpZiAoYXJyW2ldW2NvbHVtbl0gPT0gdmFsKQogICAgICAgICAgICByZXR1cm4gMTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQoKaW50IG1haW4oKQp7CiAgICBpbnQgc3VbTl1bTl07CiAgICBpbnQgaSwgajsKICAgIGludCBjb250OwoKICAgIHNyYW5kKCAodW5zaWduZWQpdGltZShOVUxMKSApOy8vZXZpdGEgcXVlIG8gcmFuZCBzZWphIGdlcmFkbyBwZWxvIHRlbXBvCgogICAgZm9yKGk9MDsgaTxOOyBpKyspCiAgICB7CiAgICAgICAgZm9yKGo9MDsgajxOOyBqKyspCiAgICAgICAgewogICAgICAgICAgICBjb250PXJhbmQoKSVOOwoKICAgICAgICAgICAgaWYoaT09Y29udCB8fCBqPT1jb250KQogICAgICAgICAgICB7CgogICAgICAgICAgICAgICAgaW50IHZhbCA9IDErcmFuZCgpJU47CgogICAgICAgICAgICAgICAgLy92ZXJpZmljYSBzZSBqw6EgZXhpc3RlIGVzdGUgdmFsb3IgbmEgbGluaGEgb3UgY29sdW5hIGF0dWFsLgogICAgICAgICAgICAgICAgaWYoaXNWYWx1ZUluTGluZU9yQ29sdW1uKHZhbCwgc3UsIGksIGopKQogICAgICAgICAgICAgICAgICAgIHN1W2ldW2pdPTA7CiAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICAgICAgc3VbaV1bal09dmFsOwoKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIC8vdXNhbmRvIDAgY29tbyBpZGVudGlmaWNhZG9yIGRlIHZhemlvCiAgICAgICAgICAgICAgICBzdVtpXVtqXT0wOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIGZvcihpPTA7IGk8TjsgaSsrKQogICAgewogICAgICAgIGZvcihqPTA7IGo8TjsgaisrKQogICAgICAgIHsKICAgICAgICAgICAgaWYoc3VbaV1bal0hPTApCiAgICAgICAgICAgICAgICBwcmludGYoIlslaV0iLCBzdVtpXVtqXSk7CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgIHByaW50ZigiWyBdIik7Ly9zZSBmb3IgaWd1YWwgYSAwIGNvbG9jYSBvIHF1YWRyYWRvIHZhemlvLgogICAgICAgIH0KICAgICAgICBwcmludGYoIlxuIik7CiAgICB9CgogICAgLyoKICAgIGZvcihpPTEgOyBpIDw9IDEwIDsgaSsrKQogICAgICAgIHByaW50ZigiTnVtZXJvICVkOiAlZFxuIixpLCAxK3JhbmQoKSU5KTsKICAgICAqLwoKCiAgICByZXR1cm4gMDsKfQ==