Advertisement
Fer22f

URI 1578

Sep 18th, 2021
956
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef unsigned long long ll;
  5.  
  6. int main() {
  7.     cin.tie(0);
  8.     ios_base::sync_with_stdio(0);
  9.  
  10.     int t;
  11.     cin >> t;
  12.  
  13.     for (int ti = 0; ti < t; ti++) {
  14.         if (ti != 0) { cout << "\n"; }
  15.         int n;
  16.         cin >> n;
  17.  
  18.         vector<vector<ll>> mat (n, vector<ll>(n));
  19.         vector<int> col (n);
  20.  
  21.         for (int i = 0; i < n; i++) {
  22.         for (int j = 0; j < n; j++) {
  23.             ll x;
  24.             cin >> x;
  25.             x *= x;
  26.             mat[i][j] = x;
  27.  
  28.             int k = 0;
  29.             while (x) { x /= 10; k++; }
  30.             col[j] = max(col[j], max(k, 1));
  31.         }
  32.         }
  33.  
  34.         cout << "Quadrado da matriz #" << ti+4 << ":\n";
  35.  
  36.         for (int i = 0; i < n; i++) {
  37.         for (int j = 0; j < n; j++) {
  38.             if (j != 0) { cout << " "; }
  39.             cout << setw(col[j]) << mat[i][j];
  40.         }
  41.             cout << "\n";
  42.         }
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement