Created
May 31, 2019 03:47
-
-
Save kei9327/8a85d9b4c60a5e83b3d287f103d6bbe6 to your computer and use it in GitHub Desktop.
HackerRank>Algorithm>Warmup>Diagonal Difference
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; | |
// Complete the diagonalDifference function below. | |
int diagonalDifference(vector<vector<int>> arr) { | |
int result = 0; | |
for(int i =0; i < arr.size();i++) { | |
result += arr[i][i] - arr[i][arr.size()-1 -i]; | |
} | |
return abs(result); | |
} | |
int main() | |
{ | |
ofstream fout(getenv("OUTPUT_PATH")); | |
int n; | |
cin >> n; | |
cin.ignore(numeric_limits<streamsize>::max(), '\n'); | |
vector<vector<int>> arr(n); | |
for (int i = 0; i < n; i++) { | |
arr[i].resize(n); | |
for (int j = 0; j < n; j++) { | |
cin >> arr[i][j]; | |
} | |
cin.ignore(numeric_limits<streamsize>::max(), '\n'); | |
} | |
int result = diagonalDifference(arr); | |
fout << result << "\n"; | |
fout.close(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment