fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void printHeartWithText(char *text) {
  5. int row, col;
  6. int width = 50; // ความกว้างโดยรวมของหัวใจ
  7. int height = 12; // ความสูงของหัวใจ
  8. int textLength = strlen(text);
  9. int textStart = (width - textLength) / 2; // ตำแหน่งเริ่มต้นของข้อความตรงกลาง
  10.  
  11. for (row = 0; row < height; row++) {
  12. for (col = 0; col <= width; col++) {
  13. // ตรวจสอบว่าอยู่ขอบของหัวใจหรือไม่
  14. if (
  15. // ส่วนขอบของหัวใจด้านบน
  16. (row < 3 && ((col == 10 - row || col == 20 + row) || (col == 30 - row || col == 40 + row))) ||
  17. // ส่วนขอบของหัวใจด้านล่าง
  18. (row >= 3 && row < 10 && (col == row * 2 - 6 || col == width - row * 2 + 6)) ||
  19. (row == 10 && (col >= row * 2 - 6 && col <= width - row * 2 + 6))
  20. ) {
  21. printf("B");
  22. } else if (row == 6 && col >= textStart && col < textStart + textLength) {
  23. // ใส่ข้อความตรงกลาง
  24. printf("%c", text[col - textStart]);
  25. } else {
  26. printf(" ");
  27. }
  28. }
  29. printf("\n");
  30. }
  31. }
  32.  
  33. int main() {
  34. char text[] = "Juthaporn";
  35. printHeartWithText(text);
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
          B         B         B         B          
         B           B       B           B         
        B             B     B             B        
B                                                 B
  B                                             B  
    B                                         B    
      B             Juthaporn               B      
        B                                 B        
          B                             B          
            B                         B            
              BBBBBBBBBBBBBBBBBBBBBBB