题解 | #圣诞树#
圣诞树
http://www.nowcoder.com/practice/9a03096ed8ab449e9b10b0466de29eb2
#include<stdio.h> void fun1(){ printf(" * "); } void fun2(){ printf(" * * "); } void fun3(){ printf("* * * "); } void fun(){ printf(" ");//输出3个空格 } int main() { int n,i,j,m; while(scanf("%d",&n)!=EOF){ for(i=1;i<=3*n;i++){ if(i%3==1){ for(m=0;m<n-1-i/3;m++){ fun(); } for(j=1;j<=i/3+1;j++){ fun1(); } printf("\n"); } if(i%3==2){ for(m=0;m<n-1-i/3;m++){ fun(); } for(j=1;j<=i/3+1;j++){ fun2(); } printf("\n"); } if(i%3==0){ for(m=0;m<n-i/3;m++){ fun(); } for(j=1;j<=i/3;j++){ fun3(); } printf("\n"); } } for(i=0;i<n;i++){ for(j=0;j<3*n-1;j++){ printf(" "); } printf("*\n"); } } return 0; }