fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(NULL);
  9.  
  10. int n;
  11. if (cin >> n) {
  12. if (n % 2 == 0) {
  13. cout << "Heart Broke\n";
  14. return 0;
  15. }
  16.  
  17. // Nửa trên của trái tim
  18. for (int i = n / 2; i <= n; i += 2) {
  19. // Khoảng trắng lề trái
  20. for (int j = 1; j < n - i; j += 2) {
  21. cout << ' ';
  22. }
  23. for (int j = 1; j <= i; ++j) {
  24. cout << '*';
  25. }
  26. for (int j = 1; j <= n - i; ++j) {
  27. cout << ' ';
  28. }
  29. // Dấu sao cánh phải
  30. for (int j = 1; j <= i; ++j) {
  31. cout << '*';
  32. }
  33. cout << "\n";
  34. }
  35.  
  36. // Nửa dưới của trái tim
  37. for (int i = n; i >= 1; --i) {
  38. for (int j = i; j < n; ++j) {
  39. cout << ' ';
  40. }
  41. for (int j = 1; j <= (i * 2) - 1; ++j) {
  42. cout << '*';
  43. }
  44. cout << "\n";
  45. }
  46. }
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty