Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int** initMat(int n) {
- int **a = NULL;
- if((a=(int**)malloc(n*sizeof(int*)))==NULL){
- printf("memorie insuficienta\n");
- exit(EXIT_FAILURE);
- }
- // alocare linii
- for(int i=0;i<n;i++){
- if((a[i]=(int*)malloc(n*sizeof(int)))==NULL){
- for(i--;i>=0;i--)free(a[i]); // elibereaza liniile alocate anterior
- free(a); // elibereaza vectorul de pointeri
- printf("memorie insuficienta\n");
- exit(EXIT_FAILURE);
- }
- }
- return a;
- }
- void readMat(int **a, int n) {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- scanf("%d", &a[i][j]);
- }
- }
- }
- void freeMat(int **a, int n) {
- for (int i = 0; i < n; i++) {
- free(a[i]);
- }
- free(a);
- }
- int ok(int **a, int n, int **b, int m, int l, int c) {
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < m; j++) {
- if (a[i + l][j + c] != b[i][j]) {
- return 0;
- }
- }
- }
- return 1;
- }
- int main(void) {
- int **a, **b, n, m;
- scanf("%d%d", &n, &m);
- a = initMat(n);
- b = initMat(m);
- readMat(a, n);
- readMat(b, m);
- for (int i = 0; i <= n - m; i++) {
- for (int j = 0; j <= n - m; j++) {
- if (ok(a, n, b, m, i, j)) {
- printf("(%d, %d) ", i, j);
- }
- }
- }
- puts("");//*/
- freeMat(a, n);
- freeMat(b, m);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement