题解
要输出空心三角形,用两个循环就可以了,第一行在第n个位置输出字符,其他输出空格,第二行在n-1和n+1处输出字符,其他输出空格,其他行类推,最后一行单独输出2n-1个字符就可以了,要注意换行的操作,不然会PE ,搞skr人。
#include<iostream>
using namespace std;
int main()
{
char a;
int n,i,j,s=0;
while (cin >> a)
{
if(a == '@') break;
if (s != 0) cout << endl;
cin >> n;
for (i = 1; i < n ; i++)
{
for (j = 1; j < n + i; j++)
{
if ( j + i-1 ==n || j-i+1==n) cout << a;
else cout << " ";
}
cout << endl;
}
for (i = 0; i < 2 * n - 1; i++)
{
cout << a;
}
cout << endl;
s = 1;
}
}