Skip to content

Instantly share code, notes, and snippets.

@estelabn
Created May 22, 2023 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save estelabn/e07877982b6039ea2d7962825baa70d0 to your computer and use it in GitHub Desktop.
Save estelabn/e07877982b6039ea2d7962825baa70d0 to your computer and use it in GitHub Desktop.
#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