Smaller Matrix Search [ZOHO] ID:2667
A bigger NxN matrix is passed as the input. Also a smaller MxM matrix is passed as input. The program must print TRUE if the smaller matrix can be found in the bigger matrix. Else the program must print FALSE.
Input Format:
First line will contain the value of N.
Second line will contain the value of M.
Next N lines will contain the values in the N*N matrix with each value separated by one or more space.
Next M lines will contain the values in the M*M matrix with each value separated by one or more space.
Output Format:
First line will contain the string value TRUE or FALSE
Boundary Conditions:
3 <= N <= 20
2 <= M <= N
Example Input/Output 1:
Input:
3
2
4 5 9
1 3 5
8 2 4
3 5
2 4
Output:
TRUE
Example Input/Output 2:
Input:
3
2
4 5 9
1 3 5
8 2 4
4 5
1 4
Output:
FALSE
PROGRAM IN C:
#include<stdio.h>
int main()
{
int n,m,a[100][100],b[100][100],i,j,p=0,q=0,c=1,f=0,k,l,o;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
scanf("%d",&b[i][j]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
p=i,q=j,o=j,c=0,k,l;
if(a[p][q]==b[k][l])
{
for(k=0;k<m;k++)
{
q=o;
for(l=0;l<m;l++)
{
if(a[p][q]==b[k][l])
{
c++;
q++;
}
else
break;
}
p++;
}
}
if(c==m*m)
{
printf("TRUE");
f=1;
}
}
}
if(f==0)
printf("FALSE");
}
Sir will anyone please help me to crack this code ?
ReplyDeletechar str[100];
int strlen;
Scanf( );
Printf("%d",strlen);
IT HAVE TO ACCEPT THE STRING AND OUTPUT WILL BE IN INTEGER