Created
February 1, 2018 12:09
-
-
Save hckim16/af58a8b0bc438d515826f6c0346dd97e to your computer and use it in GitHub Desktop.
Summing across diagonals and abs value of subtracting diagonal sums
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 <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
int main(){ | |
int n; | |
cin >> n; | |
vector< vector<int> > a(n,vector<int>(n)); | |
for(int a_i = 0;a_i < n;a_i++){ | |
for(int a_j = 0;a_j < n;a_j++){ | |
cin >> a[a_i][a_j]; | |
} | |
} | |
int sum1=0,sum2=0; | |
for(int i=0, k=n-1; i< n; i++, k--){ | |
for(int j=0; j< n; j++){ | |
cin >> a[i][j]; | |
if(i==j) | |
sum1 += a[i][j]; | |
} | |
sum2 += a[i][k]; | |
} | |
cout << abs(sum1-sum2); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment