#include <iostream>
using namespace std;
int dx[8] = {-1,0,1,-1,1,-1,0,1};
int dy[8] = {-1,-1,-1,0,0,1,1,1};
int main() {
    int cnt = 0;
    int cnt2 = 0;
    int arr[5][5];
    int num[5][5];
    int visited[5][5] = {0,};
    for(int i = 0;i < 5;i++){
        for(int j = 0;j < 5;j++){
            cin >> arr[i][j];
        }
    }
    for(int i = 0;i < 5;i++){
        for(int j = 0;j < 5;j++){
            cin >> num[i][j];
        }
    } 
    int row[5] = {0,};
        int coll[5] = {0,};
        int left = 0;
        int right = 0;
        for(int b = 0;b < 5;b++){
            for(int k = 0;k < 5;k++){
                for(int i = 0;i < 5;i++){
                    for(int j = 0;j < 5;j++){
                        if(num[b][k] == arr[i][j]){
                            cnt2++;
                            row[i]++;
                            if(row[i] == 5)
                            {cnt++;
                            row[i] = 0;
                            //cout << row[i] << "\n"; 
                            }
                            coll[j]++;
                            if(coll[j] == 5)
                            {cnt++;
                            coll[j] = 0;
                            //cout << coll[j] << "\n";
                            }
                            if(i==j) left++;
                            if(i+j==4) 
                            {right++;
                            //cout << i <<" " << j<< "\n";
                            }
                            if(left == 5){
                            cnt++;
                            left = 0;
                            }
                            if(right == 5){
                            //cout << right << "\n";
                            cnt++;
                            right = 0;
                            }
                        }
                    }
                }
            if(cnt >= 3){
            cout << cnt2;
            return 0;
            }
        }        
    }
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: