版权声明:转载请附上原文链接哟! https://blog.csdn.net/weixin_44170305/article/details/89842063
如花美眷,似水流年,回得了过去,回不了当初。
中国的古人写文字,是从右向左竖向排版的。本题就请你编写程序,把一段文字按古风排版。
输入格式:
输入在第一行给出一个正整数N(<100),是每一列的字符数。第二行给出一个长度不超过1000的非空字符串,以回车结束。
输出格式:
按古风格式排版给定的字符串,每列N个字符(除了最后一列可能不足N个)。
输入样例:
4
This is a test case
输出样例:
asa T
st ih
e tsi
ce s
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
char s[1005],a[105][105];
using namespace std;
int main()
{
int n,i=0,j,k;
scanf("%d",&n);
getchar();
char c;
while(1)
{
c=getchar();
if(c=='\n')
break;
s[i]=c;
i++;
}
int t=strlen(s),l=0;
int m=(t+n-1)/n;
for(j=m-1; j>=0; j--)
{
for(k=0; k<n; k++)
{
if(l<t)
a[k][j]=s[l++];
else
a[k][j]=' ';
}
}
for(int j=0; j<n; j++)
{
for(int k=0; k<m; k++)
cout<<a[j][k];
cout<<endl;
}
return 0;
}