/* HDU 2091 空心三角形 --- 水题 */ #include <cstdio> int main() { int kase = 0; char ch; int h, t; //h表示高 while (scanf("%c", &ch) == 1 && ch != ‘@‘){ scanf("%d", &h); if (kase++){ printf("\n"); } getchar(); if (h == 1){ //注意1的时候特殊处理 printf("%c\n", ch); continue; } //第一行 for (int i = 0; i < h - 1; ++i) printf(" "); printf("%c\n", ch); //2 - h-1行 for (int i = 2; i < h; ++i){ //n-i个空 t = h - i; for (int j = 0; j < t; ++j) printf(" "); printf("%c", ch); //2(i-2)+1个空 t = 2 * (i - 2) + 1; for (int j = 0; j < t; ++j){ printf(" "); } printf("%c\n", ch); } //n行 t = 2 * h - 1; for (int i = 0; i < t; ++i) printf("%c", ch); printf("\n"); } return 0; }
时间: 2024-12-25 03:16:18