cf 118B
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:
0
0 1 0
0 1 2 1 0
0 1 2 3 2 1 0
0 1 2 3 4 3 2 1 0
0 1 2 3 4 5 4 3 2 1 0
0 1 2 3 4 3 2 1 0
0 1 2 3 2 1 0
0 1 2 1 0
0 1 0
0
Your task is to determine the way the handkerchief will look like by the given n.
The first line contains the single integer n (2 ≤ n ≤ 9).
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
2
0
0 1 0
0 1 2 1 0
0 1 0
0
3
0
0 1 0
0 1 2 1 0
0 1 2 3 2 1 0
0 1 2 1 0
0 1 0
0
1 #include<map> 2 #include<cmath> 3 #include<queue> 4 #include<cstdio> 5 #include<vector> 6 #include<string> 7 #include<cstring> 8 #include<sstream> 9 #include<iostream> 10 #include<algorithm> 11 using namespace std; 12 int main() 13 { 14 int n; 15 cin>>n; 16 for(int i = 0 ; i < n + 1; i ++) 17 { 18 for(int j = 0 ; j < i * 2 + 1 ; j ++) 19 { 20 for(int k = i*2 ; j==0 && k < n * 2 ; k++ )cout<<" "; 21 if(j<=i&&j!=i*2)cout<<j<<" "; 22 else if(j<=i)cout<<j; 23 else if(j!=i*2)cout<<i*2-j<<" "; 24 else cout<<i*2-j; 25 } 26 cout<<endl; 27 } 28 for(int i = 0 ; i < n ; i++) 29 { 30 for(int j = 0 ; j < (n - i )* 2 - 1 ; j++) 31 { 32 for(int k = 0 ; j==0&& k < (i+1)*2 ; k++)cout<<" "; 33 if(j<=n-i-1 && j!= (n-i)*2-2)cout<<j<<" "; 34 else if(j<=n-i-1)cout<<j; 35 else if(j!=(n-i)*2-2)cout<<(n-i -1)*2 -j <<" "; 36 else cout<<(n-i-1)*2-j; 37 } 38 cout<<endl; 39 40 } 41 }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步