fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cmath>
  4. #include <ctime>
  5. #include <cstring>
  6.  
  7. const unsigned int pass_number = 10;
  8. const int max_x = 20;
  9. const int max_y = 20;
  10.  
  11. template<int>
  12. bool in_figure(int x, int y);
  13.  
  14. template<>
  15. bool in_figure<1>(int x, int y)
  16. {
  17. return y < max_y && x < max_x && (x + y - max_y + 1) >= 0;
  18. }
  19.  
  20. template<>
  21. bool in_figure<2>(int x, int y)
  22. {
  23. return y < max_y && x < max_x && (x + y - max_y + 1) >= 0 && (y - x) >= 0;
  24. }
  25.  
  26. int main()
  27. {
  28. char buffer[max_y][max_x];
  29.  
  30. srand(time(0));
  31. memset(buffer, ' ', max_y * max_x);
  32.  
  33. for (unsigned pass = 0; pass < pass_number; ++pass)
  34. for (int y = 0; y < max_y; ++y)
  35. for (int x = 0; x < max_x; ++x)
  36. if (buffer[y][x] != 'x')
  37. if ((rand() % (pass_number / 3) == 0) && in_figure<1>(x, y))
  38. buffer[y][x] = (buffer[y][x] == ' ')?'.':(buffer[y][x] == '.')?'v':'x';
  39.  
  40. for (int y = 0; y < max_y; ++y)
  41. {
  42. for (int x = 0; x < max_x; ++x)
  43. std::cout << buffer[y][x];
  44. std::cout << std::endl;
  45. }
  46. }
  47.  
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
                   x
                  xx
                 xx.
                xx.v
               xv.xv
              xxxxx.
             xvvvvx.
            xxxxxxvx
           xxvxxxxvx
          xxxxxxxxvx
         xxxxxxvvxv.
        xvxxvxxxxxvx
       xxx.xxxxxx xx
       xxxvxx.xxxx.x
     .xvxvxxxxxxxxxx
    xxxvvxxx .vxxxx 
   .xxxxxxvxxxxxvvvv
  xxxx.xxxvxx.xxxxxx
 xxxvxxxvxxx.xvxxxvx
.x.xxv.x.xxx xxxxxvx