题目描述
由键盘输入任意一个自然数N,输出如下图规律的图形。
输入
只有一个整数N,为图形上半部分的行数(其中2<=N<=9)
输出
输出指定格式的图形。
样例输入
5
样例输出
5 8 4 7 3 6 2 5 1 4 0 4 1 5 2 6 3 7 4 8 5
这个有亿点点难,代码如下:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int i,j,m,a,b,n;
cin >> n;
m = n;
a = m;
b = m;
for(i = m;i >= 1;i--)
{
for(j = i - 1;j >= 1;j--)
{
cout << " ";
}
for(j = m;j >= a;j--)
{
cout << (char)(j + 64);
}
for(j = a + 1;j <= m;j++)
{
cout << (char)(j + 64);
}
a = a - 1;
cout << endl;
}
a = 2;
for(i = 2;i <= m;i++)
{
for(j = 1;j <= i - 1;j++)
{
cout << " ";
}
if(i != m)
{
for(j = m;j >= a;j--)
{
cout << (char)(j + 64);
}
for(j = a + 1;j <= m;j++)
{
cout << (char)(j + 64);
}
}
else
{
cout << (char)(n + 64);
}
a = a + 1;
cout << endl;
}
return 0;
}