fork(1) download
  1. #include <array>
  2. #include <iostream>
  3.  
  4. constexpr std::size_t kSize = 10;
  5.  
  6. void PrintLine(std::size_t i, char left, char right) {
  7. std::array<char, kSize * 2 + 1> buffer;
  8. auto first = buffer.begin();
  9. auto last = buffer.end() - 2;
  10. auto pos = first;
  11. while (pos != first + i) *pos++ = ' ';
  12. *pos++ = left;
  13. while (pos != last - i) *pos++ = ' ';
  14. *pos++ = right;
  15. *pos++ = '\n';
  16. std::cout.write(first, pos - first);
  17. }
  18.  
  19. int main() {
  20. std::size_t i = kSize;
  21.  
  22. while (i != 0) {
  23. --i;
  24. PrintLine(i, '/', '\\');
  25. }
  26.  
  27. while (i != kSize) {
  28. PrintLine(i, '\\', '/');
  29. ++i;
  30. }
  31. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
         /\
        /  \
       /    \
      /      \
     /        \
    /          \
   /            \
  /              \
 /                \
/                  \
\                  /
 \                /
  \              /
   \            /
    \          /
     \        /
      \      /
       \    /
        \  /
         \/