Prova questo che funziona
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
void matching_migliore (int a[][10] , int b[][3] , int c , int col_cost , int row_cost);
int punteggio_migliore (int a[][10] , int b[][3] , int c , int col_cost , int row_cost , int iColx , int iRowx);
void stampaMatrice (int mx[][10] , int col , int row);
int main ()
{
/*
int cielo [10][10]={0}; */
int cielo [10][10]= { {0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0} };
int coste[4][3]={{1,0,1},
{0,1,0},
{1,0,1},
{1,0,1}};
int foo;
int x,y;
int i,j;
int indice=0,indiceRow,indiceCol;
srand(time(0));
for (i=0;i<=25;i++)
{
x=rand()%11;
y=rand()%11;
if (cielo[x][y]==1)
i=i-1;
else
cielo[x][y]=1;
}
for (i=0;i<10;i++)
{
for (j=0;j<10;j++)
printf("%d ",cielo[i][j]);
printf("\n");
}
printf("\n\n");
for (i=0;i<4;i++)
{
for (j=0;j<3;j++)
printf("%d ",coste[i][j]);
printf("\n");
}
printf("\n");
matching_migliore (cielo , coste , 10 , 3 , 4);
scanf("%d" , &foo);
}
void stampaMatrice (int mx[][10] , int col , int row)
{
printf("MATRICE RISULTATO :\n");
printf("-------------------\n");
for (int i = row ; i < 4+row ; i++)
{
for(int j = col ; j < 3+col ; j++)
{
printf("%d " , mx[i][j]);
}
printf("\n");
}
}
int punteggio_migliore (int a[][10] , int b[][3] , int c , int col_cost , int row_cost , int iColx , int iRowx)
{
int iC, iR , n_caratteri_uguali;
n_caratteri_uguali=0;
for (iR=iRowx ; iR < 4 + iRowx ; iR++)
{
for (iC=iColx ; iC < 3 + iColx ; iC++)
{
// printf ("==== iR : %d iC : %d a : %d b : %d \n ",iR,iC,a[iR][iC],b[iR-iRowx][iC-iColx]);
if (a[iR][iC] == b[iR-iRowx][iC-iColx])
{
n_caratteri_uguali++;
}
}
}
// printf("Punt : %d iCol : %d iRow : %d \n" , n_caratteri_uguali , iColx , iRowx);
return n_caratteri_uguali;
}
void matching_migliore (int a[][10] , int b[][3] , int c , int col_cost , int row_cost)
{
int iCol , iRow , resultCol , resultRow , punteggio_max, punteggio;
punteggio_max=0;
for (iRow=0 ; iRow <= (c - row_cost) ; iRow++)
{
for (iCol=0 ; iCol <= (c - col_cost) ; iCol++)
{
punteggio=punteggio_migliore (a , b , c , col_cost , row_cost , iCol , iRow );
if (punteggio > punteggio_max)
{
punteggio_max=punteggio;
resultRow=iRow;
resultCol=iCol;
// printf("--------> iRow : %d iCol : %d ", iRow, iCol);
}
}
}
// stampaMatrice(a , resultCol , resultRow);
stampaMatrice(a , resultCol , resultRow);
printf("Col : %d Row : %d Numero coincidenze : %d" , resultCol+1 , resultRow+1 , punteggio_max);
}