Skip to content

Instantly share code, notes, and snippets.

@bingli224
Created February 25, 2019 16:54
Show Gist options
  • Save bingli224/2bd14c34f6c4ecc475a1700a1baf18c5 to your computer and use it in GitHub Desktop.
Save bingli224/2bd14c34f6c4ecc475a1700a1baf18c5 to your computer and use it in GitHub Desktop.
// 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