Skip to content

Instantly share code, notes, and snippets.

@hckim16
Created February 1, 2018 12:09
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 hckim16/af58a8b0bc438d515826f6c0346dd97e to your computer and use it in GitHub Desktop.
Save hckim16/af58a8b0bc438d515826f6c0346dd97e to your computer and use it in GitHub Desktop.
Summing across diagonals and abs value of subtracting diagonal sums
#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