Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int n,sch,level=2,level2=2,x,y,o=4;
  6. int a[1000][1000];
  7.  
  8. int main()
  9. {
  10.     cin>>n;
  11.  
  12.     x=n-1;
  13.     y=n+1;
  14.  
  15.     while (o--)
  16.     {
  17.         for (int i=0;i<level2;i++)
  18.         {
  19.             y--;
  20.             sch++;
  21.             a[x][y]=sch;
  22.         }
  23.         for (int i=0;i<level;i++)
  24.         {
  25.             x++;
  26.             sch++;
  27.             a[x][y]=sch;
  28.         }
  29.  
  30.         for (int i=0;i<level;i++)
  31.         {
  32.             y++;
  33.             sch++;
  34.             a[x][y]=sch;
  35.  
  36.         }
  37.         for (int i=0;i<=level;i++)
  38.         {
  39.             x--;
  40.             sch++;
  41.             a[x][y]=sch;
  42.         }
  43.         level+=2;
  44.  
  45.         if (level==2)
  46.             level2=2;
  47.         else
  48.         if (level==4)
  49.             level2=3;
  50.         else
  51.             level2+=2;
  52.  
  53.     }
  54.  
  55.     for (int i=0; i<2*n+1; i++)
  56.     {
  57.         for (int j=0; j<2*n+1; j++)
  58.             if (a[i][j]>9)
  59.                 cout<<a[i][j]<<" ";
  60.             else
  61.                 cout<<a[i][j]<<"  ";
  62.         cout<<endl;
  63.     }
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement