View Code of Problem 17

#include<stdlib.h>
#include<stdio.h>


int n,m;

int search(int i,int j){
	if(stair[i][j]>stair[i+1][j] && stair[i][j]>stair[i-1][j] && stair[i][j]>stair[i][j+1] && stair[i][j]>stair[i][j-1])
		return 0;
	
	int l=0,u=0,r=0,d=0;
	if(stair[i][j]<stair[i][j-1]){
		l = 1 + search(i,j-1); 
	}

	if(stair[i][j]<stair[i-1][j]){
		u = 1 + search(i-1,j); 
	}

	if(stair[i][j]<stair[i][j+1]){
		r = 1 + search(i,j+1); 
	}

	if(stair[i][j]<stair[i+1][j]){
		d = 1 + search(i+1,j); 
	}

	int max1,max2;
	if (l>r)
		max1 = l;
	else 
		max1 = r;

	if(u>d)
		max2 = u;
	else
		max2 = d;

	int max;
	if(max1 > max2)
		max = max1;
	else
		max = max2;
	return max;

}


int main(){
	while((scanf("%d %d",&n,&m)!=EOF)){
		int stair[1000][1000]={0};
	
		for(int i=1; i<=n; i++){
			for(int z=1; z<=m; z++)
				scanf("%d",&stair[i][z]);
		}
		int max=0;
		for(int i=1; i<=n; i++){
			for(int z=1; z<=m; z++){
				int result = search(i,z);
				if(result > max)
					max = result;
			}
		}
		printf("%d\n",max);
	}
	return 0;
}
/*
Main.cc: In function 'int search(int, int)':
Main.cc:8:5: error: 'stair' was not declared in this scope
  if(stair[i][j]>stair[i+1][j] && stair[i][j]>stair[i-1][j] && stair[i][j]>stair[i][j+1] && stair[i][j]>stair[i][j-1])
     ^~~~~
Main.cc:8:5: note: suggested alternative: 'stdin'
  if(stair[i][j]>stair[i+1][j] && stair[i][j]>stair[i-1][j] && stair[i][j]>stair[i][j+1] && stair[i][j]>stair[i][j-1])
     ^~~~~
     stdin
Main.cc:12:5: error: 'stair' was not declared in this scope
  if(stair[i][j]<stair[i][j-1]){
     ^~~~~
Main.cc:12:5: note: suggested alternative: 'stdin'
  if(stair[i][j]<stair[i][j-1]){
     ^~~~~
     stdin
Main.cc:16:5: error: 'stair' was not declared in this scope
  if(stair[i][j]<stair[i-1][j]){
     ^~~~~
Main.cc:16:5: note: suggested alternative: 'stdin'
  if(stair[i][j]<stair[i-1][j]){
     ^~~~~
     stdin
Main.cc:20:5: error: 'stair' was not declared in this scope
  if(stair[i][j]<stair[i][j+1]){
     ^~~~~
Main.cc:20:5: note: suggested alternative: 'stdin'
  if(stair[i][j]<stair[i][j+1]){
     ^~~~~
     stdin
Main.cc:24:5: error: 'stair' was not declared in this scope
  if(stair[i][j]<stair[i+1][j]){
     ^~~~~
Main.cc:24:5: note: suggested alternative: 'stdin'
  if(stair[i][j]<stair[i+1][j]){
     ^~~~~
     stdin
*/

Double click to view unformatted code.


Back to problem 17