STANAANDREY

tema 5/17/2021

May 17th, 2021 (edited)
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define NMAX 1'000
  4. int n, arr[NMAX][NMAX];
  5.  
  6. void read() {
  7.   cin >> n;
  8.   for (int i = 1; i <= n; i++) {
  9.     for (int j = 1; j <= n; j++) {
  10.       cin >> arr[i][j];
  11.     }
  12.   }
  13. }
  14.  
  15. void getSum() {
  16.   int sum = 0;
  17.   for (int i = 2; i < n; i++) {
  18.     int j = n - 1;
  19.     while (true) {
  20.       if (i <= (n + 1) / 2) {
  21.         if (j == n - i + 1) {
  22.           break;
  23.         }
  24.       } else {
  25.         if (i == j) {
  26.           break;
  27.         }
  28.       }
  29.       sum += arr[i][j];
  30.       j--;
  31.     }
  32.   }
  33.   cout << sum << endl;
  34. }
  35.  
  36. int main() {
  37.   read();
  38.   getSum();
  39.   return 0;
  40. }
  41.  
Add Comment
Please, Sign In to add comment