Advertisement
Spocoman

04. Diagonal Difference

Jan 26th, 2024
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int n, el;
  9.     cin >> n;
  10.  
  11.     vector<vector<int>> matrix;
  12.  
  13.     for (int i = 0; i < n; i++) {
  14.         vector<int> currentRow;
  15.         for (int j = 0; j < n; j++) {
  16.             cin >> el;
  17.             currentRow.push_back(el);
  18.         }
  19.         matrix.push_back(currentRow);
  20.     }
  21.  
  22.     int diff = 0;
  23.  
  24.     for (int i = 0; i < n; i++) {
  25.         diff += matrix[i][i];
  26.     }
  27.  
  28.     for (int i = 0; i < n; i++) {
  29.         diff -= matrix[i][n - (1 + i)];
  30.     }
  31.  
  32.     cout << abs(diff) << endl;
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement