fork download
  1. #include<stdio.h>
  2. #define cBYTES_OF_ZENKAKU 3 /*S-JIS全角文字のバイト数。処理系依存*/
  3. #define Limit_of_chara 35 /*11×3+2*/
  4.  
  5. const int cTOTAL_GYO=11;
  6. const char cWHITE_SHIKAKU[]="□";
  7. /* const char cBLACK_SHIKAKU[]="■"; */
  8. const char cZENKAKU_SPACE[]=" ";
  9. const char cHANKAKU_SPACE=' ';
  10.  
  11. /*汎用関数。第一引数に未完成のchar配列の中で追記したい位置、第二引数に追記したい文字列(マルチバイト文字など)へのポインタを渡す
  12. EOSは最後に1つ追加。第三引数は繰り返し回数*/
  13. void write_in_array(char *archp, const char* const start_of_str, const int role_times){
  14. static const char nulmoji = '\0';
  15. const char* p_to_str = start_of_str;
  16. int i;
  17. for(i=0;i<role_times;i++){
  18. while(*p_to_str != nulmoji){
  19. *archp = *p_to_str;
  20. archp++;
  21. p_to_str++;
  22. }
  23. p_to_str = start_of_str;
  24. }
  25. *archp = nulmoji;
  26. }
  27.  
  28. /*main()より呼び出される*/
  29. void show_top(const int k){
  30. int c,kk;
  31. char arch[Limit_of_chara]="";
  32.  
  33. for(c=1;c<cTOTAL_GYO;c++){
  34. kk=c / 2;
  35. write_in_array(&arch[0], cZENKAKU_SPACE, k-kk);
  36. if(c % 2==0){
  37. arch[(k-kk)*cBYTES_OF_ZENKAKU] = cHANKAKU_SPACE;
  38. write_in_array(&arch[(k-kk)*cBYTES_OF_ZENKAKU+1], cWHITE_SHIKAKU, c);
  39. } else {
  40. write_in_array(&arch[(k-kk)*cBYTES_OF_ZENKAKU], cWHITE_SHIKAKU, c);
  41. }
  42. printf("%s\n", arch);
  43. }
  44. }
  45.  
  46. /*main()より呼び出される*/
  47. void show_bottom(const int k){
  48. char arch[Limit_of_chara]="";
  49. write_in_array(&arch[0], cZENKAKU_SPACE, k);
  50. printf("%s%s\n",arch, cWHITE_SHIKAKU);
  51. }
  52.  
  53. int main(void){
  54. const int k=(cTOTAL_GYO / 2) +1;
  55. show_top(k);/*樹幹部分の構築*/
  56. show_bottom(k);/*幹部分の構築*/
  57. return 0;
  58. }
Success #stdin #stdout 0s 2112KB
stdin
Standard input is empty
stdout
      □
      □□
     □□□
     □□□□
    □□□□□
    □□□□□□
   □□□□□□□
   □□□□□□□□
  □□□□□□□□□
  □□□□□□□□□□
      □