es de vida o muerte- por favor
Bueno casi casi, porque si no precento este trabajo mañana no tendre derecho a examen. Ayudenme por favor :+(
Tengo que hacer un programa que calcule cuantas veces una matriz pequeña se encuentra dentro de una grande. Llevo dias trabajo en ello y no consigo que funcione al 100%. Y ya se me agota el tiempo :+(
El codigo que escribi es este, ayudenme y diganme que esta mal, por que a veces funciona y otras no funciona. Un millon de gracias.
#include<stdio.h>
void main()
{
int m,n,num,i,j,k,l,count,count1;
int conta=0,flag;
int big[50][50],smal[50][50];
printf(\"Enter how much shurot in the first array\");
scanf(\"%d\",&m);
printf(\"Enter the numbers\");
for(i=0;i<m;i++)
for(j=0;j<m;j++)
{
scanf(\"%d\",&num);
big[i][j]=num;
}
printf(\"Enter how much shurot inthe secong array\");
scanf(\"%d\",&n);
printf(\"Enter the numbers\");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf(\"%d\",&num);
smal[i][j]=num;
}
for(i=0;i<=m-n;i++)
for(j=0;j<=m-n;j++)
{
flag=1;
for(k=i,count=0;(count<n)&&flag;count++,k++)
for(l=j,count1=0;(count1<n)&&flag;count1++,l++)
{
if(big[k][l]!=smal[count][count1])
flag=0;
}
if(flag)
conta++;
}
printf(\"martrixa smal esta dentro de matrixa bid %d veces\",conta);
}
Tengo que hacer un programa que calcule cuantas veces una matriz pequeña se encuentra dentro de una grande. Llevo dias trabajo en ello y no consigo que funcione al 100%. Y ya se me agota el tiempo :+(
El codigo que escribi es este, ayudenme y diganme que esta mal, por que a veces funciona y otras no funciona. Un millon de gracias.
#include<stdio.h>
void main()
{
int m,n,num,i,j,k,l,count,count1;
int conta=0,flag;
int big[50][50],smal[50][50];
printf(\"Enter how much shurot in the first array\");
scanf(\"%d\",&m);
printf(\"Enter the numbers\");
for(i=0;i<m;i++)
for(j=0;j<m;j++)
{
scanf(\"%d\",&num);
big[i][j]=num;
}
printf(\"Enter how much shurot inthe secong array\");
scanf(\"%d\",&n);
printf(\"Enter the numbers\");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf(\"%d\",&num);
smal[i][j]=num;
}
for(i=0;i<=m-n;i++)
for(j=0;j<=m-n;j++)
{
flag=1;
for(k=i,count=0;(count<n)&&flag;count++,k++)
for(l=j,count1=0;(count1<n)&&flag;count1++,l++)
{
if(big[k][l]!=smal[count][count1])
flag=0;
}
if(flag)
conta++;
}
printf(\"martrixa smal esta dentro de matrixa bid %d veces\",conta);
}
Te mando un programam que hace parte del trabajo : determina si una matriz se encuentra dentro de una mas grande, pero lo hace una sola vez. No es ningun problema modificar el programa para repetir el proceso.
Te deseo el mejor de los exitos.
// program k5c1.CPP - page 91
// for two given matrix large[M][N] and small[P][Q]
// check if small is a submatrix of large.
// c++ exercices book - dr. gershon kagan (first edition : 2001)
// written in Borland CPP ver 3.1
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#define M 5
#define N 7
#define P 3
#define Q 2
int large[M][N] = {{ 12, -5, 18, 4, 5, 0, 7},
{ 1, 6, 0, -4, 12, -5, -8},
{ 3,-17, 9, 2, 0, 6, 1},
{ -3, 0, 10, 11, -3, 17,-15},
{ 11, 6, -2, -1,-12, 14, 2}};
int small[P][Q] = {{ 12, -5},
{ 0, 6},
{ -3, 17}};
void Show(int *a,int R,int S,char *msg)
{
for(int i = 0; i < R; i++)
{
cout << setw(20) << msg;
msg[0] = 0;
for(int j = 0; j < S; j++)
cout << setw(5) << *(a+i*S+j);
cout << endl;
}
cout << endl;
} // SHOW
void Process()
{
for(int row = 0; row <= M-P; row++)
for(int col = 0; col <= N-Q; col++)
{
int ok = 1;
for(int i = 0; i < P && ok; i++)
for(int j = 0; j < Q && ok; j++)
ok = small[i][j] == large[row+i][col+j];
if(ok)
cout << "small is a sub matrix of large, begins at "
<< "<" << row << "," << col << ">" << endl << endl;
}
} // PROCESS
void main()
{
clrscr();
cout << "for two given matrix large[M][N] and small[P][Q]" << endl;
cout << "check if small is a submatrix of large." << endl << endl;
Show(&large[0][0],M,N,"large : ");
Show(&small[0][0],P,Q,"small : ");
Process();
cout << "end of program - good bye ! ! !" << endl;
getch();
} // MAIN
/*
for two given matrix large[M][N] and small[P][Q]
check if small is a submatrix of large.
large : 12 -5 18 4 5 0 7
1 6 0 -4 12 -5 -8
3 -17 9 2 0 6 1
-3 0 10 11 -3 17 -15
11 6 -2 -1 -12 14 2
small : 12 -5
0 6
-3 17
small is a sub matrix of large, begins at <1,4>
end of program - good bye ! ! !
*/
Te deseo el mejor de los exitos.
// program k5c1.CPP - page 91
// for two given matrix large[M][N] and small[P][Q]
// check if small is a submatrix of large.
// c++ exercices book - dr. gershon kagan (first edition : 2001)
// written in Borland CPP ver 3.1
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#define M 5
#define N 7
#define P 3
#define Q 2
int large[M][N] = {{ 12, -5, 18, 4, 5, 0, 7},
{ 1, 6, 0, -4, 12, -5, -8},
{ 3,-17, 9, 2, 0, 6, 1},
{ -3, 0, 10, 11, -3, 17,-15},
{ 11, 6, -2, -1,-12, 14, 2}};
int small[P][Q] = {{ 12, -5},
{ 0, 6},
{ -3, 17}};
void Show(int *a,int R,int S,char *msg)
{
for(int i = 0; i < R; i++)
{
cout << setw(20) << msg;
msg[0] = 0;
for(int j = 0; j < S; j++)
cout << setw(5) << *(a+i*S+j);
cout << endl;
}
cout << endl;
} // SHOW
void Process()
{
for(int row = 0; row <= M-P; row++)
for(int col = 0; col <= N-Q; col++)
{
int ok = 1;
for(int i = 0; i < P && ok; i++)
for(int j = 0; j < Q && ok; j++)
ok = small[i][j] == large[row+i][col+j];
if(ok)
cout << "small is a sub matrix of large, begins at "
<< "<" << row << "," << col << ">" << endl << endl;
}
} // PROCESS
void main()
{
clrscr();
cout << "for two given matrix large[M][N] and small[P][Q]" << endl;
cout << "check if small is a submatrix of large." << endl << endl;
Show(&large[0][0],M,N,"large : ");
Show(&small[0][0],P,Q,"small : ");
Process();
cout << "end of program - good bye ! ! !" << endl;
getch();
} // MAIN
/*
for two given matrix large[M][N] and small[P][Q]
check if small is a submatrix of large.
large : 12 -5 18 4 5 0 7
1 6 0 -4 12 -5 -8
3 -17 9 2 0 6 1
-3 0 10 11 -3 17 -15
11 6 -2 -1 -12 14 2
small : 12 -5
0 6
-3 17
small is a sub matrix of large, begins at <1,4>
end of program - good bye ! ! !
*/
