View Code of Problem 3499

#include<stdio.h>
#include<math.h>
#include<string.h>
int step(int a[5][5],int i,int j)//找路 ,右下左上的顺序找路 
{
	if(i==4&&j==4)
	{
		a[i][j]=2;
		return 1;
	}
	else 
	{
		if(a[i][j]==0)
		{
			a[i][j]=2;
			if(i+1<5&&step(a,i+1,j)==1)
			return 1;
			else if(j+1<5&&step(a,i,j+1)==1)
			return 1;
			else if(i-1>=0&&step(a,i-1,j)==1)
			return 1;
			else if(j-1>=0&&step(a,i,j-1)==1)
			return 1;
			else 
			{
				a[i][j]=3; 
				return 0;
			}
		}
	}
	return 0;
}
int main()
{	
	int a[5][5];
		for(int i=0;i<5;i++)
		{
			for(int j=0;j<5;j++)
			{	
				scanf("%d",&a[i][j]);	
			}
		}
		step(a,0,0);
		for(int i=0;i<5;i++)
		{
			for(int j=0;j<5;j++)
			{
				if(a[i][j]==2)
				{
					printf("(%d,%d)\n",i,j);
				}
			}
		}
		
}

Double click to view unformatted code.


Back to problem 3499