How do I get the vector with the smallest "me", and copy it to another vector that the case calls "mnr"

0

Note: I did not start the code because it does not influence!

I'm trying to pass the coordinates of the array that has the smallest number of zeros in your column, row, or quadrant (to make a sudoku solver). Thanks so much!

  int main(){
        int mat[9][9];
        le_arquivo("sudoku.txt", mat);


        int i,j,k;
        for(i=0; i< 9; i++){
            for(j=0; j< 9; j++)
                printf("%d ",mat[i][j]);

            printf("\n");
        }

        int ex[4], me, mnr[3] = {0,0,9,0};

        for(i=0; i< 9; i++){
            for(j=0; j< 9; j++){
                readZeros(i,j, mat, ex, mnr[4]);
                if(ex[2] > mnr[2]){
                    for(k = 0; k < 4; k++){
                        printf("%d", ex[k]);
                    }
                }
            }
        }
        for(i=0;i < 4; i++){
            printf("%d", mnr[i]);
        }

    }

    //Funcao que pega o numero de zeros
    void readZeros(int x, int y, int mat[9][9], int ex[4], int mnr[4]){
        int i, j, n = 0, me = 0, tp;

        //Pegando numero de zeros da linha
        for(i = 0; i < 9; i++){
            if(mat[x][i] == 0){
                n++;
            }
        }
        tp = 0;
        me = n;

        n = 0;

        //Pegando numero de zeros da coluna
        for(i = 0; i < 9; i++){
            if(mat[x][i] == 0){
                n++;
            }

        }
        if(n < me){
            me = n;
            tp = 1;
        }
        n = 0;

        //Pegando numero de zeros do quadrante

        if(x < 3){
            x = 0;
        }else if(x < 6){
            x = 3;
        }else if(x < 9){
            x = 6;
        }

        if(y < 3){
            y = 0;
        }else if(y < 6){
            y = 3;
        }else if(y < 9){
            y = 6;
        }

        for(i = x; i < (x + 3); i++){
            for(j = y; j < (y + 3); j++){
                if(mat[i][j] == 0){
                    n++;
                }
            }
        }
        if(n < me){
            me = n;
            tp = 2;
        }
        n=0;

        ex[0] = x;
        ex[1] = y;
        ex[2] = me;
        ex[3] = tp;
    }
    
asked by anonymous 04.12.2018 / 02:18

0 answers