Description |
使用循环结构打印如下图形: 1 212 32123 4321234 32123 212 1 |
Input |
有多组数据,第一行一个正整数t(t<100)表示输入数据组数,接下来有t组输入数据,每组数据占一行,包含一个整数a,1<=a<=100。 |
Output |
对于每组数据,输出一个菱形,菱形总行数为2*a+1。左侧使用空格占位,右侧没有空格。请不要输出多余空格。 |
Sample Input |
1 1 |
Sample Output |
1 212 1 |
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
int t,ans=0;
cin>>t;
while(t--)
{
int a;
cin>>a;
for(int i=1;i<=2*a+1;i++)
{
for(int j=1;j<=abs(i-a-1);j++) cout<<" ";
for(int j=a+1-abs(i-a-1);j>0;j--) cout<<j;
for(int j=2;j<=a+1-abs(i-a-1);j++) cout<<j;
cout<<endl;
}
}
return 0;
}