Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int a[1000][1000];
  6.  
  7. int main() {
  8.     int n;            
  9.     cin >> n;
  10.     int m = n*2 + 1;
  11.     int c = m*m;
  12.     for (int i = 0; i < n; ++i) {
  13.         for (int j = i + 1; j <= m - i; ++j) {
  14.             a[j][m - i] = --c;
  15.         }
  16.         for (int j = m - i - 1; j >= i + 1; --j) {
  17.             a[m - i][j] = --c;
  18.         }
  19.         for (int j = m - i - 1; j >= i + 1; --j) {
  20.             a[j][i + 1] = --c;
  21.         }
  22.         for (int j = i + 2; j <= m - i - 1; ++j) {
  23.             a[i + 1][j] = --c;
  24.         }
  25.     }
  26.     for (int i = 1; i <= m; ++i) {
  27.         for (int j = 1; j <= m; ++j) {
  28.             int len = 0;
  29.             int x = a[i][j];
  30.             if (x == 0)
  31.                 len = 1;
  32.             while (x) {
  33.                 len++;
  34.                 x /= 10;
  35.             }
  36.             while (len++ < 3) {
  37.                 cout << ' ';
  38.             }
  39.             cout << a[i][j];
  40.         }
  41.         cout << endl;
  42.     }
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement