Created
February 25, 2019 16:54
-
-
Save bingli224/2bd14c34f6c4ecc475a1700a1baf18c5 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
// 23:53 THA 25/02/2019 | |
// by BingLi224 | |
// Reference: https://www.hackerrank.com/challenges/30-2d-arrays/problem | |
#include <bits/stdc++.h> | |
using namespace std; | |
int main() | |
{ | |
vector<vector<int>> arr(6); | |
for (int i = 0; i < 6; i++) { | |
arr[i].resize(6); | |
for (int j = 0; j < 6; j++) { | |
cin >> arr[i][j]; | |
} | |
cin.ignore(numeric_limits<streamsize>::max(), '\n'); | |
} | |
int max = -9 * 7; | |
int sz = arr.size ( ) - 2; | |
int idxX = 0; | |
int idxY; | |
while ( idxX < sz ) { | |
idxY = 0; | |
while ( idxY < sz ) { | |
int sum = arr [ idxX ] [ idxY ] + arr [ idxX ] [ idxY + 1 ] + arr [ idxX ] [ idxY + 2 ] + arr [ idxX + 1 ] [ idxY + 1 ] + arr [ idxX + 2 ] [ idxY ] + arr [ idxX + 2 ] [ idxY + 1 ] + arr [ idxX + 2 ] [ idxY + 2 ]; | |
if ( sum > max ) | |
max = sum; | |
idxY ++; | |
} | |
idxX ++; | |
} | |
cout << max << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment