中国的古人写文字,是从右向左竖向排版的。本题就请你编写程序,把一段文字按古风排版。
输入格式:
输入在第一行给出一个正整数N(<100),是每一列的字符数。第二行给出一个长度不超过1000的非空字符串,以回车结束。
输出格式:
按古风格式排版给定的字符串,每列N个字符(除了最后一列可能不足N个)
输入样例:
4
This is a test case
输出样例:
asa T
st ih
e tsice s
【注】:这个题的关键就是格式,感觉当时比赛时一次就AC也是比较幸运的
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <cstdlib> #include <string> #include <stack> #include <queue> using namespace std; char s[1010]; int main() { int t = 0; int n, m; scanf("%d", &n); getchar(); gets(s); int len = strlen(s); m = len / n; if (len > m*n) m++; for (int j = 0; j < n; j++) { for (int i = m-1; i >= 0; i--) { if (i*n+j >= len) printf(" "); else { printf("%c", s[i*n+j]); } } printf("n"); } return 0; }
最后
以上就是唠叨柠檬最近收集整理的关于古风排版的全部内容,更多相关古风排版内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复