codeforce Present from Lena 打印菱形
来源:互联网 发布:java工作日报 编辑:程序博客网 时间:2024/06/15 17:52
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 00 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 00 1 2 1 0 0 1 0 0
3
0 0 1 0 0 1 2 1 00 1 2 3 2 1 0 0 1 2 1 0 0 1 0 0
细心题目,没更好的办法了,一个一个字符去打印,安排出菱形。
这里分上下菱形分别打印。
#include <iostream>using namespace std;void PresentfromLena(){int k = 0;cin>>k;for (int i = 0; i <= k; i++){int space = k - i;for (int j = 0; j < space; j++){cout<<" ";}for (int j = 0; j <= i; j++){cout<<j;if (0 != i) cout<<' ';}for (int j = i - 1; j >= 0 ; j--){cout<<j;if (j != 0) cout<<' ';}cout<<endl;//不要遗忘了换行符}for (int i = k - 1; i >= 0 ; i--){int space = k - i;for (int j = 0; j < space; j++){cout<<" ";}for (int j = 0; j <= i; j++){cout<<j;if (0 != i) cout<<' ';}for (int j = i - 1; j >= 0 ; j--){cout<<j;if (j != 0) cout<<' ';}cout<<endl;}}
- codeforce Present from Lena 打印菱形
- B. Present from Lena
- Present from Lena
- Codeforces 118B Present from Lena
- codeforces 118B Present from Lena
- Codeforces Beta Round #89 (Div. 2) B. Present from Lena
- 打印菱形
- 打印菱形
- 打印菱形
- 打印菱形
- 打印菱形
- 打印菱形
- 打印菱形
- 打印菱形
- 打印菱形
- 打印菱形
- 打印菱形
- 打印菱形
- sublime text2/3怎样在windows中配置ctags插件
- CCSpriteBatchNode读取plist
- C++中,如何执行一个控制台命令并返回结果到字符串string中
- jobschu boa、cgi组合利用html到cgi的实现代码
- Valid Parentheses
- codeforce Present from Lena 打印菱形
- Android读写配置文件
- cocos2d-x3.0 相对布局(一)
- java socket 多线程
- CM之过程总览
- maven下载及环境设置备忘
- Hibernate(二)
- 初学Java,枚举类(二十二)
- C#网络编程 异步