Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <bits/stdc++.h>
- using namespace std;
- void solve() {
- int N;
- cin>>N;
- if(N>=2 && N<=100) {
- vector<vector<int>> M(N);
- for(int i=0; i<N; i++) {
- int input;
- for(int j=0; j<N; j++) {
- cin>>input;
- if(input>=1 && input<=N) M[i].push_back(input);
- }
- }
- int k=0, r=0, c=0;
- // calculate k
- for(int i=0; i<N; i++) {
- k += M[i][i];
- }
- for(int i=0; i<N; i++) {
- //calculate r
- vector<int> copy_r = M[i];
- sort(copy_r.begin(), copy_r.end());
- int count_r = 1;
- for(int j=1; j<N; j++) {
- if(copy_r.at(j) == copy_r.at(j-1)) {
- count_r++;
- } else {
- count_r = 1;
- }
- if(count_r > r) r = count_r;
- }
- // calculate c
- vector<int> copy_c;
- for(int j=0; j<N; j++) {
- copy_c.push_back(M[j][i]);
- }
- sort(copy_c.begin(), copy_c.end());
- int count_c = 1;
- for(int j=1; j<N; j++) {
- if(copy_c.at(j) == copy_c.at(j-1)) {
- count_c++;
- } else {
- count_c = 1;
- }
- if(count_c > c) c = count_c;
- }
- }
- if(r == 1) r = 0;
- if(c == 1) c = 0;
- cout << k << " " << r << " " << c << "\n";
- }
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- long long int T;
- int x=1;
- cin >> T;
- if(T>=1 && T<=100) {
- while(T--) {
- cout << "Case #" << x << ": ";
- solve();
- x++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement