基础题。
#include <iostream>
using namespace std;
int main()
{
int N;
cin >> N;
char c; //字符
int h; //高度
int upH, downH; //上半部高度,下半部高度
int sideW, midW; //边缘宽度,中间宽度
while (N--)
{
cin >> c >> h;
if ((h - 3) % 2 == 0)
upH = downH = (h - 3) / 2;
else
{
upH = (h - 3) / 2;
downH = upH + 1;
}
sideW = h / 6 + 1;
midW = downH;
for (int i = 0; i < h; i++)
{
if (i == 0 || i == upH + 1 || i == h - 1)
{
for (int j = 0; j < sideW; j++)
cout << " ";
for (int j = 0; j < midW; j++)
cout << c;
}
else
{
for (int j = 0; j < sideW; j++)
cout << c;
for (int j = 0; j < midW; j++)
cout << " ";
for (int j = 0; j < sideW; j++)
cout << c;
}
cout << endl;
}
if (N != 0)
cout << endl;
}
return 0;
}
继续加油。