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 textLength = strlen(text);
  8. int textStart = (width - textLength) / 2; // ตำแหน่งเริ่มต้นของข้อความตรงกลาง
  9.  
  10. for (row = 0; row < 12; row++) {
  11. for (col = 0; col <= width; col++) {
  12. // ส่วนของหัวใจด้านบน
  13. if (
  14. (row < 3 && ((col > 10 - row && col < 20 + row) || (col > 30 - row && col < 40 + row))) ||
  15. // ส่วนของหัวใจด้านล่าง
  16. (row >= 3 && row < 10 && col > row * 2 - 6 && col < width - row * 2 + 6) ||
  17. (row >= 10 && col > row * 2 - 6 && col < width - row * 2 + 6)
  18. ) {
  19. // ใส่ข้อความตรงกลาง
  20. if (row == 6 && col >= textStart && col < textStart + textLength) {
  21. printf("%c", text[col - textStart]);
  22. } else {
  23. printf("B");
  24. }
  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
           BBBBBBBBB           BBBBBBBBB           
          BBBBBBBBBBB         BBBBBBBBBBB          
         BBBBBBBBBBBBB       BBBBBBBBBBBBB         
 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB 
   BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB   
     BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB     
       BBBBBBBBBBBBBJuthapornBBBBBBBBBBBBBBB       
         BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB         
           BBBBBBBBBBBBBBBBBBBBBBBBBBBBB           
             BBBBBBBBBBBBBBBBBBBBBBBBB             
               BBBBBBBBBBBBBBBBBBBBB               
                 BBBBBBBBBBBBBBBBB