古风排版

来源:互联网 发布:淘宝首页有什么服务 编辑:程序博客网 时间:2024/06/11 02:01

Problem A: 古风排版

Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 24 Solved: 10
[Submit][Status][Web Board]

Description

中国的古人写文字,是从右向左竖向排版的。本题就请你编写程序,把一段文字按古风排版。

Input

输入在第一行给出一个正整数N(<100),是每一列的字符数。第二行给出一个长度不超过1000的非空字符串,以回车结束。

Output

按古风格式排版给定的字符串,每列N个字符(除了最后一列可能不足N个)

Sample Input

4This is a test case

Sample Output

asa Tst ihe tsi ce s

记得初始化!

memset(b, ' ', sizeof(b));  初始化为‘\0’错误。


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char a[1000];
char b[100][100];
int main(){
memset(b, ' ', sizeof(b));
int N;
cin >> N;
getchar();
cin.getline(a, 100);
int len = strlen(a);
int col = len / N;
int md = len%N;
for (int j = 1; j <= md; j++)
b[j][0] = a[len - md + j - 1];

int cre = 0;
for (int j = col; j >= 1; j--)
for (int i = 1; i <= N; i++){
b[i][j] = a[cre];
cre++;
}
int jj = 0;
if (md == 0) jj = 1;
else jj = 0;
for (int i = 1; i <= N; i++){
for (int j = jj; j <= col; j++)
cout << b[i][j];
if (i != N)cout << endl;
}


return 0;
}








0 0