题206.2022寒假天梯赛训练-7-8 古风排版 (20 分)
一、题目
二、题解
yysy,这道题我第一次做是在去年寒假,到现在这是第四回了,前三回一次都没有满分过,直到这次我才发现输出排版后的字符时,那空着的是空格,所以初始化输出数组时要注意先把它用空格初始化一下。。。
#include <bits/stdc++.h>
using namespace std;
char output[201][201];
int main()
{
fill(output[0],output[0]+201*201,' ');//切记开始一定要先用空格初始化output数组,输出中没字符的部分其实就是空格!!!
int N;
cin>>N;
string str;
getchar();
getline(cin,str);
int len=str.length();
int k=0;
int j,i;
for(j=200; j>0; j--)//因为它排版是从右到左,从上到下,所以我干脆直接从二维数组最右边开始排字符了,然后先动行再动列
{
for(i=0; i<N; i++)
{
output[i][j]=str[k++];
//cout<<k<<endl;
if(k==len)
{
break;
}
}
if(k==len)
{
break;
}
}
int x0=0,y0=j;//确定字符在二维数组开始的位置
//cout<<y0<<endl;
for(i=0; i<N; i++)
{
for(j=y0; j<=200; j++)
{
cout<<output[i][j];
//printf("%c",output[i][j]);
}
putchar('\n');
}
}