Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     ios::sync_with_stdio(0);
  8.     cin.tie(0);
  9.     int t;
  10.     cin >> t;
  11.     for (int i = 0; i < t; i ++) {
  12.         int n;
  13.         int diag = 0, tmp;
  14.         cin >> n;
  15.  
  16.         int arr[n][n];
  17.         for (int j = 0; j < n; j ++){
  18.             for (int k = 0; k < n; k ++) {
  19.                 cin >> arr[j][k];
  20.                 if (j == k)
  21.                     diag += arr[j][k];
  22.             }
  23.         }
  24.         int rows = 0;
  25.         int cols = 0;
  26.  
  27.         for (int j = 0; j < n; j ++) {
  28.             int histR[n + 1] = {0};
  29.             int histC[n + 1] = {0};
  30.             for (int k = 0; k < n; k ++){
  31.                 histR[arr[j][k]] ++;
  32.                 histC[arr[k][j]] ++;
  33.             }
  34.            for (int k = 1; k <= n; k ++){
  35.                 if (histR[k] > 1){
  36.                     rows ++;
  37.                     break;
  38.                 }
  39.             }
  40.  
  41.            
  42.            for (int k = 1; k <= n; k ++){
  43.                 if (histC[k] > 1){
  44.                     cols ++;
  45.                     break;
  46.                 }
  47.             }
  48.         }
  49.  
  50.  
  51.    
  52.         cout << "Case #" << i + 1 << ": " << diag << " " << rows << " " << cols;
  53.         if (i != t - 1)
  54.             cout << endl;
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement