Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. void solve() {
  7.     int N;
  8.     cin>>N;
  9.  
  10.     if(N>=2 && N<=100) {
  11.         vector<vector<int>> M(N);
  12.  
  13.         for(int i=0; i<N; i++) {
  14.             int input;
  15.             for(int j=0; j<N; j++) {
  16.                 cin>>input;
  17.                 if(input>=1 && input<=N) M[i].push_back(input);
  18.             }
  19.         }
  20.  
  21.         int k=0, r=0, c=0;
  22.  
  23.         // calculate k
  24.         for(int i=0; i<N; i++) {
  25.             k += M[i][i];
  26.         }
  27.  
  28.         for(int i=0; i<N; i++) {
  29.             //calculate r
  30.             vector<int> copy_r = M[i];
  31.             sort(copy_r.begin(), copy_r.end());
  32.             int count_r = 1;
  33.             for(int j=1; j<N; j++) {
  34.                 if(copy_r.at(j) == copy_r.at(j-1)) {
  35.                     count_r++;
  36.                 } else {
  37.                     count_r = 1;
  38.                 }
  39.                 if(count_r > r) r = count_r;
  40.             }
  41.            
  42.  
  43.             // calculate c
  44.             vector<int> copy_c;
  45.             for(int j=0; j<N; j++) {
  46.                 copy_c.push_back(M[j][i]);
  47.             }
  48.             sort(copy_c.begin(), copy_c.end());
  49.             int count_c = 1;
  50.  
  51.             for(int j=1; j<N; j++) {
  52.                 if(copy_c.at(j) == copy_c.at(j-1)) {
  53.                     count_c++;
  54.                 } else {
  55.                     count_c = 1;
  56.                 }
  57.                 if(count_c > c) c = count_c;
  58.             }
  59.         }
  60.         if(r == 1) r = 0;
  61.         if(c == 1) c = 0;
  62.         cout << k << " " << r << " " << c << "\n";
  63.     }
  64. }
  65.  
  66. int main() {
  67.     ios::sync_with_stdio(0);
  68.     cin.tie(0);
  69.  
  70.     long long int T;
  71.     int x=1;
  72.     cin >> T;
  73.     if(T>=1 && T<=100) {
  74.         while(T--) {
  75.             cout << "Case #" << x << ": ";
  76.             solve();
  77.             x++;
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement