题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2091
注意格式,每一行没有多余的空格,最后一个三角形后没有空行。
#include<iostream>
using namespace std;
int main()
{
char e;
int n, x, y, judge = 0;
while ((cin >> e) && e != '@')
{
cin >> n;
if (judge)
cout << endl;
judge = 1;
for (int i = 0; i <= n-2; i++)
{
x = n - i; y = n + i;
for (int j = 1; j <= y; j++)
{
if (j == x || j == y)
cout << e;
else
cout << " ";
}
cout << endl;
}
for (int i = 1; i <= 2 * n - 1; i++)
cout << e;
cout << endl;
}
return 0;
}