convert c++ code to csharp(c#)

  • Thread starter Thread starter sabih411
  • Start date Start date
S

sabih411

Guest
bool maze(char a[1000][1000],int i,int j,int m,int n,int tari,int tarj,int r[][1000],int hor,int ver)
{

//cout<<hor<<""<<ver<<" ";
if(i==tari&&j==tarj)
{

r[i][j]=1;
for(int k=0;k<m;k++)
{

for(int l=0;l<n;l++)
{

cout<<r[k][l]<<" ";
}

cout<<endl;
}

cout<<endl;
return true;
}

r[i][j]=1;
if(a[i][j+1]!='X'&&j+1<n&&ver==1)
{

bool rightsebaatbangayi=maze(a,i,j+1,m,n,tari,tarj,r,hor,ver);
if(rightsebaatbangayi)
{

return true;
}
}

if(a[i][j-1]!='X'&&j-1>n&&ver==0)
{

bool leftsebaatbangayi=maze(a,i,j-1,m,n,tari,tarj,r,hor,ver);
if(leftsebaatbangayi13wz)
{

return true;
}
}

if(a[i+1][j]!='X'&&i+1<m&&hor==1)
{

bool neechesebaatbangayi=maze(a,i+1,j,m,n,tari,tarj,r,hor,ver);
if(neechesebaatbangayi)
{

return true;
}
}

if(a[i-1][j]!='X'&&i-1>0&&hor==0)
{

bool uparsebaatbangayi=maze(a,i-1,j,m,n,tari,tarj,r,hor,ver);
if(uparsebaatbangayi)
{

return true;
}
}

r[i][j]=0;
return false;
}

int main() {
int n=6,m=7,tari,tarj,curi,curj;
cin>>curi>>curj;
cin>>tari>>tarj;
char maze1[1000][1000];
bool ans;
for(int i=0; i<n;i++)
{

for(int j=0;j<m;j++)
{

cin>>maze1[i][j];
}
}

int sol[1000][1000]={0};
//case 1
//if any one is in top or bottom lane

if (tari==5||tari==0||curi==0||curi==5)
{

if(curi<tari)
{
//neeche
if(curj<tarj)
{

//right
ans=maze(maze1,curi,curj,n,m,tari,tarj,sol,1,1);
}

else
{
//left
ans=maze(maze1,curi,curj,n,m,tari,tarj,sol,1,0);
}
}

if(curi>tari)
{
//upar
if(curj<tarj)
{

//right
ans=maze(maze1,curi,curj,n,m,tari,tarj,sol,0,1);
}

else
{
//left
ans=maze(maze1,curi,curj,n,m,tari,tarj,sol,0,0);
}
}
}

// ans=maze(maze1,curi,curj,n,m,tari,tarj,sol);
if(!ans)
{

cout<<"-1";
}
}


Continue reading...
 
Back
Top