Don't like ads? PRO users don't see any ads ;-)
Guest

Donov Gilbert laba

By: a guest on Apr 26th, 2012  |  syntax: C++  |  size: 1.34 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2.  
  3. #define _height 4000
  4. #define _width 4000
  5. using namespace std;
  6.  
  7. static const int maxX = _height, maxY = _width;
  8. int maxx=0, maxy=0,_time=0;
  9. int x=0, y=0;
  10. char a[_height][_width];
  11.  
  12.  
  13. int per(int type)
  14.  {
  15.   switch (type)
  16.    {
  17.         case 0: a[++x][y] = '|';
  18. ++x; break;
  19.         case 1: a[x][++y] = '-';
  20. ++y; break;
  21.         case 2: a[--x][y] = '|';
  22. --x; break;
  23.         case 3: a[x][--y] = '-';
  24. --y; break;
  25.    }
  26.  }
  27.  
  28. int go(int t, int k, int n)
  29.  {
  30.    if (n == 0)
  31.     { if (x<maxX && y<maxY)
  32.           {
  33.                         a[x][y] = '*';
  34.                         if (x > maxx) maxx = x;
  35.                         if (y > maxy) maxy = y;
  36.                 }
  37.           return 1;
  38.     }
  39.     if (t>0)
  40.      {
  41.        if (k==0)  return  (go(-t,1,n-1) + per(2) + go(t,0,n-1) + per(3) + go(t,0,n-1) + per(0) + go(-t,3,n-1));
  42.            if (k==2) return   (go(-t,3,n-1) + per(0) + go(t,2,n-1) + per(1) + go(t,2,n-1) + per(2) + go(-t,1,n-1));
  43.  
  44.         } else
  45.          {
  46.            if (k==1) return  (go(-t,0,n-1) + per(3) + go(t,1,n-1) + per(2) + go(t,1,n-1) + per(1) + go(-t,2,n-1));
  47.            if (k==3) return  (go(-t,2,n-1) + per(1) + go(t,3,n-1) + per(0) + go(t,3,n-1) + per(3) + go(-t,0,n-1));
  48.         }
  49.  }
  50.  
  51. int main()
  52.  {
  53.         int n;
  54.         cin >> n;
  55.         for (int i=0;i<_height; i++)
  56.         for (int j=0;j<_width;j++)
  57.         a[i][j]=' ';
  58.         go(1,2,n);
  59.         for (int i = maxx; i>=0; i--)
  60.         {
  61.                 for (int j = 0 ; j<=maxy; j++)
  62.                 cout << a[i][j];
  63.                 cout<<endl;
  64.         }
  65.         system("pause");
  66.         return 0;
  67.  }