Question 206.2022 Winter Holiday Ladder Competition Training-7-8 Antique Typesetting (20 points)


Question 206.2022 Winter Holiday Ladder Competition Training-7-8 Antique Typesetting (20 points)


1. The topic

insert image description here

2. Problem solving

yysy, I did this question for the first time during the winter vacation last year. Now this is the fourth time. I haven't gotten full marks in the first three times. Only this time I found out that when I output the typesetting characters, the blank It is a space, so when initializing the output array, pay attention to initializing it with a space first. . .

#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');
    }

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324345975&siteId=291194637