Smallest Rectangle
Input :(place 1 as rock other wise 0)
5 4
0 0 0 0
0 1 0 0
0 0 0 1
1 0 0 0
0 0 0 0
Output: (1,0), (1,3), (3,0), (3,3)
*/
#include<stdio.h>
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
int main()
{
int m,n,A[10][10],i,j,i1=10,i2=0,j1=10,j2=0;
printf("enter m & n (m*n) :");
scanf("%d %d",&m,&n);
printf("entet array (place 1 as rock other wise 0) :\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&A[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(A[i][j]==1)
{
i1=MIN(i1,i);
i2=MAX(i2,i);
j1=MIN(j1,j);
j2=MAX(j2,j);
}
printf("\n(%d,%d), (%d,%d), (%d,%d), (%d,%d)\n",i1,j1,i1,j2,i2,j1,i2,j2);
return 0;
}
No comments:
Post a Comment