fork download
  1. #include <iostream>
  2. #include <utility>
  3.  
  4. template <std::size_t... Is>
  5. auto print_sword(int n, std::index_sequence<Is...>) {
  6. static constexpr char sp[] = " ";
  7. static constexpr char ds[] = "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------";
  8.  
  9. using expander = int[];
  10. (void)expander{0, (
  11. (static_cast<int>(Is) + 1 <= 3 * n - 1) ? (
  12. [&]() {
  13. int i = static_cast<int>(Is) + 1;
  14. int left_spaces = (i <= n) ? (n - i + 1) / 2 :
  15. (i < 2 * n) ? (i - n + 1) / 2 :
  16. (3 * n - i) / 2;
  17.  
  18. if (i == n) {
  19. if (n == 1) {
  20. std::cout.write("*\n", 2);
  21. } else {
  22. std::cout.put('*');
  23. std::cout.write(ds, 2 * n - 3);
  24. std::cout.write("*\n", 2);
  25. }
  26. } else if (i > 1 && i < 2 * n - 1) {
  27. int P = (n + 1) / 2;
  28. int inner = P - left_spaces - 1;
  29. std::cout.write(sp, left_spaces);
  30. std::cout.put('*');
  31. std::cout.write(sp, inner);
  32. std::cout.put('|');
  33. std::cout.write(sp, inner);
  34. std::cout.write("*\n", 2);
  35. } else {
  36. std::cout.write(sp, left_spaces);
  37. std::cout.write("*\n", 2);
  38. }
  39. }(), 0
  40. ) : 0
  41. )...};
  42. }
  43.  
  44. auto main() -> int {
  45. std::ios_base::sync_with_stdio(false);
  46. std::cin.tie(nullptr);
  47.  
  48. int n;
  49. if (std::cin >> n) {
  50. print_sword(n, std::make_index_sequence<300>{});
  51. }
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0s 5320KB
stdin
10
stdout
     *
    *|*
    *|*
   * | *
   * | *
  *  |  *
  *  |  *
 *   |   *
 *   |   *
*-----------------*
 *   |   *
 *   |   *
  *  |  *
  *  |  *
   * | *
   * | *
    *|*
    *|*
     *
     *
    *
    *
   *
   *
  *
  *
 *
 *
*