题解 | #字符圣诞树#
字符圣诞树
https://www.nowcoder.com/practice/0fae60c3b5c64699b7c0f031c2187dde
#include <stdio.h> int main() { char a; scanf("%c", &a); //一定要找规律,md无语死,我分了5条情况分析但没必要 //规律就是先是空格,然后是打印,空格加打印总共是5个,每次打印的时候要加一个空格 for (int i = 0; i < 5; i ++) { int j; switch (i) { case 0: for (j = 0; j < 5; ) { j++; if (j == 5) printf("%c", a); printf(" "); } break; case 1: for (j = 1; j <= 5; j++) { if (j == 4 || j == 5) printf("%c", a); printf(" "); } break; case 2: for (j = 1; j <= 5; j++) { if (j == 3 || j == 4 || j == 5) printf("%c", a); printf(" "); } break; case 3: for (j = 1; j <= 5; j++) { if ( j == 2 ||j == 3 || j == 4 || j == 5) printf("%c", a); printf(" "); } break; case 4: for (j = 1; j <= 5; j++) { if ( j == 1 ||j == 2 ||j == 3 || j == 4 || j == 5) printf("%c", a); printf(" "); } break; } printf("\n"); } return 0; // char a; // scanf("%c", &a); // for (int i = 1; i <= 5; i++) { // for (int j = 5 - i; j > 0; j--) // printf(" "); // for (int m = 1; m <= i; m++) // printf("%c ", a); // printf("\n"); // } // return 0; }#C语言基础练习#