Created
May 22, 2023 01:22
-
-
Save estelabn/e07877982b6039ea2d7962825baa70d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
int a[4] = {1,2,3,4}; | |
bool valid(int x, int y){ | |
if(x>=0 and x<15 and y>=0 and y<15) return true; | |
return false; | |
} | |
int m[15][15]; | |
int main(){ | |
for(int i=0; i<15; i++) for(int j=0; j<15; j++) cin >> m[i][j]; | |
int res = 0; | |
for(int i=0; i<15; i++) for(int j=0; j<15; j++){ | |
if(m[i][j] == 0) continue; | |
// para horizontal direita | |
for(int l = 0; l<4; l++){ | |
if(!valid(i, j + a[l]))break; | |
if(m[i][j + a[l]] != m[i][j]) break; | |
if(l == 3) res = m[i][j]; | |
} | |
// para vertical baixo | |
for(int l = 0; l<4; l++){ | |
if(!valid(i+a[l], j)) break; | |
if(m[i+a[l]][j] != m[i][j]) break; | |
if(l == 3) res = m[i][j]; | |
} | |
// diagonal baixo direita | |
for(int l = 0; l<4; l++){ | |
if(!valid(i+a[l], j+a[l])) break; | |
if(m[i+a[l]][j+a[l]] != m[i][j]) break; | |
if(l == 3) res = m[i][j]; | |
} | |
// diagonal baixo esquerda | |
for(int l = 0; l<4; l++){ | |
if(!valid(i+a[l], j - a[l])) break; | |
if(m[i+a[l]][j-a[l]] != m[i][j]) break; | |
if(l == 3) res = m[i][j]; | |
} | |
} | |
cout << res << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment