What Is Wrong With That c++ nice solution


#1

#include

int i=0;
int j=0;
int flag=0;

void safeIIncrease(vector<vector >& mat,int A);
void safeJIncrease(vector<vector >& mat,int A);
void safeJDecrease(vector<vector >& mat,int A);
void safeIDecrease(vector<vector >& mat,int A);

void safeJIncrease(vector<vector >& mat,int A)
{
// if (flag==-4)
// {
// throw 1;
// }

if (j!=A-1)
{
    if (mat[i][j+1]==0)
    {
        j++;
        flag=0;
    }
    else
    {
        safeIIncrease(mat,A); 
        flag--;
    }
}
else
{
    safeIIncrease(mat,A);
    flag--;
}

}

void safeIIncrease(vector<vector >& mat,int A)
{
if (i!=A-1)
{
if (mat[i+1][j]==0)
{
i++;
flag=0;
}
else
{
safeJDecrease(mat,A);
flag–;
}
}
else
{
safeJDecrease(mat,A);
flag–;
}
}

void safeJDecrease(vector<vector >& mat,int A)
{
if (j!=0)
{
if (mat[i][j-1]==0)
{
j–;
flag=0;
}
else
{
safeIDecrease(mat,A);
flag–;
}
}
else
{
safeIDecrease(mat,A);
flag–;
}
}

void safeIDecrease(vector<vector >& mat,int A)
{
if (i!=0)
{
if (mat[i-1][j]==0)
{
i–;
flag=0;
}
else
{
safeJIncrease(mat,A);
flag–;
}
}
else
{
safeJIncrease(mat,A);
flag–;
}
}

vector<vector > Solution::generateMatrix(int A) {

int value=1;
vector<vector<int> > mat(A,vector<int>(A,0));

while (value<=pow(A,2))
{
    mat[i][j]=value;

    value++;
 
   safeJIncrease(mat,A);
    
   
}

return mat;

}