#include<stdio.h>
#include<stdlib.h>
#include <time.h>
#define D 9
#define F 4
void criarSudoku(int dificuldade);
int isValueInLineOrColumn(int val, char** arr, int tamanho, int line, int column);
int conferencia;
int main()
{
int opc=0;
printf("1-facil\t2-medio\t3-dificil");
conferencia=opc;
criarSudoku(conferencia);
return 0;
}
void criarSudoku(int dificuldade)
{
int tamanho;
if(dificuldade==1)
tamanho = F;
else
tamanho = D;
FILE *arquivo;
char **mesa;// = new char [tamanho][tamanho];
int i, j;
switch(dificuldade)
{
case 1:
arquivo
=fopen("facil.txt","r"); break;
case 2:
arquivo
=fopen("medio.txt","r"); break;
case 3:
arquivo
=fopen("dificil.txt","r"); break;
}
for(i=0; i<tamanho; i++)
{
for(j=0; j<tamanho; j++)
{
while((mesa
[i
][j
]=fgetc(arquivo
))!=EOF
) {
}
}
}
arquivo
=fopen("dificil.txt","a");
for(i=0; i<tamanho; i++)
{
for(j=0; j<tamanho; j++)
{
int val
= 1+rand()%tamanho
;
while((mesa[i][j]=0))
{
if(isValueInLineOrColumn(val, mesa, tamanho, i, j))
fprintf(arquivo
,"%c", mesa
[i
][j
]=0); else
fprintf(arquivo
,"%c", mesa
[i
][j
]=val
); }
}
}
}
int isValueInLineOrColumn(int val, char** arr, int tamanho, int line, int column)
{
int i;
for (i=0; i < tamanho; i++)
{
if(arr[line][i] == val)
return 1;
if (arr[i][column] == val)
return 1;
}
return 0;
}
ICNpbmNsdWRlPHN0ZGlvLmg+CiAgICAjaW5jbHVkZTxzdGRsaWIuaD4KICAgICNpbmNsdWRlIDx0aW1lLmg+CgogICAgI2RlZmluZSBEIDkKICAgICNkZWZpbmUgRiA0CgogICAgdm9pZCBjcmlhclN1ZG9rdShpbnQgZGlmaWN1bGRhZGUpOwogICAgaW50IGlzVmFsdWVJbkxpbmVPckNvbHVtbihpbnQgdmFsLCBjaGFyKiogYXJyLCBpbnQgdGFtYW5obywgaW50IGxpbmUsIGludCBjb2x1bW4pOwoKICAgIGludCBjb25mZXJlbmNpYTsKCiAgICBpbnQgbWFpbigpCiAgICB7CiAgICAgICAgaW50IG9wYz0wOwoKICAgICAgICBwcmludGYoIjEtZmFjaWxcdDItbWVkaW9cdDMtZGlmaWNpbCIpOwogICAgICAgIHNjYW5mKCIlZCIsICZvcGMpOwogICAgCiAgICAgICAgY29uZmVyZW5jaWE9b3BjOwoKICAgICAgICBjcmlhclN1ZG9rdShjb25mZXJlbmNpYSk7CgogICAgICAgIHJldHVybiAwOwogICAgfQoKCiAgICB2b2lkIGNyaWFyU3Vkb2t1KGludCBkaWZpY3VsZGFkZSkKICAgIHsKICAgIAlpbnQgdGFtYW5obzsKICAgIAkKICAgIAlpZihkaWZpY3VsZGFkZT09MSkKICAgIAkJdGFtYW5obyA9IEY7CiAgICAJZWxzZQogICAgCQl0YW1hbmhvID0gRDsKICAgIAkKICAgICAgICBGSUxFICphcnF1aXZvOwogICAgICAgIGNoYXIgKiptZXNhOy8vID0gbmV3IGNoYXIgW3RhbWFuaG9dW3RhbWFuaG9dOwogICAgICAgIGludCBpLCBqOwogICAgCiAgICAgICAgc3JhbmQoICh1bnNpZ25lZCl0aW1lKE5VTEwpICk7CiAgICAgICAgCiAgICAgICAgc3dpdGNoKGRpZmljdWxkYWRlKQogICAgICAgIHsKICAgICAgICAJY2FzZSAxOgogICAgICAgIAkJYXJxdWl2bz1mb3BlbigiZmFjaWwudHh0IiwiciIpOwogICAgICAgIAkJYnJlYWs7CiAgICAgICAgCQkKICAgICAgICAJY2FzZSAyOgogICAgICAgIAkJYXJxdWl2bz1mb3BlbigibWVkaW8udHh0IiwiciIpOwogICAgICAgIAkJYnJlYWs7CiAgICAgICAgCQkKICAgICAgICAJY2FzZSAzOgogICAgICAgIAkJYXJxdWl2bz1mb3BlbigiZGlmaWNpbC50eHQiLCJyIik7CiAgICAgICAgCQlicmVhazsKICAgICAgICB9CgogICAgICAgIGZvcihpPTA7IGk8dGFtYW5obzsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgZm9yKGo9MDsgajx0YW1hbmhvOyBqKyspCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHdoaWxlKChtZXNhW2ldW2pdPWZnZXRjKGFycXVpdm8pKSE9RU9GKQogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgZmZsdXNoKHN0ZGluKTsKICAgICAgICAgICAgICAgICAgICAgICAgcHJpbnRmKCAiJWMiLCBtZXNhW2ldW2pdKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAKICAgICAgICBmY2xvc2UoYXJxdWl2byk7CiAgICAKICAgICAgICBhcnF1aXZvPWZvcGVuKCJkaWZpY2lsLnR4dCIsImEiKTsKICAgIAogICAgICAgIGZvcihpPTA7IGk8dGFtYW5obzsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgZm9yKGo9MDsgajx0YW1hbmhvOyBqKyspCiAgICAgICAgICAgIHsKICAgICAgICAJICAgIGludCB2YWwgPSAxK3JhbmQoKSV0YW1hbmhvOwogICAgICAgIAkKICAgICAgICAJICAgIHdoaWxlKChtZXNhW2ldW2pdPTApKQoJCQkgICAgewoJCQkJICAgIGlmKGlzVmFsdWVJbkxpbmVPckNvbHVtbih2YWwsIG1lc2EsIHRhbWFuaG8sIGksIGopKQoJCQkJICAgIAlmcHJpbnRmKGFycXVpdm8gLCIlYyIsIG1lc2FbaV1bal09MCk7CgkJCSAgICAJZWxzZQoJCQkgICAgCQlmcHJpbnRmKGFycXVpdm8gLCIlYyIsIG1lc2FbaV1bal09dmFsKTsKCQkgICAgCX0JCgkgICAgCX0KCSAgICB9CgkKCQogICAgfQoKICAgIGludCBpc1ZhbHVlSW5MaW5lT3JDb2x1bW4oaW50IHZhbCwgY2hhcioqIGFyciwgaW50IHRhbWFuaG8sIGludCBsaW5lLCBpbnQgY29sdW1uKQogICAgewogICAgICAgIGludCBpOwoKICAgICAgICBmb3IgKGk9MDsgaSA8IHRhbWFuaG87IGkrKykKICAgICAgICB7CiAgICAgICAgICAgIGlmKGFycltsaW5lXVtpXSA9PSB2YWwpCiAgICAgICAgICAgICAgICByZXR1cm4gMTsKCiAgICAgICAgICAgIGlmIChhcnJbaV1bY29sdW1uXSA9PSB2YWwpCiAgICAgICAgICAgICAgICByZXR1cm4gMTsKICAgICAgICB9CgogICAgICAgIHJldHVybiAwOwogICAgfQ==