排版问题算法

排版问题算法的基本思路:将排版转化为一个二维char数组或者int数组,挖掘所给要求中存在的二维数组内部的数学、逻辑关系,并用代码表示出来。
在这里插入图片描述
这里采用的代码如下:

/*画图问题——叠框*/
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main()
{
    int len;char B;char A;
    while(scanf("%d %c %c",&len,&B,&A)!=EOF){
        if(((len+1)/2)%2!=0){
            char tmp;
            tmp = B;B = A;A = tmp;
        }
        char ch[100][100]={' '};
        int hlen = (len+1)/2;
        for(int i=2;i<=len-1;i++){
            ch[1][i] = A;
        }
        for(int i=2;i<=len-1;i++){
            ch[len][i] = A;
        }
        for(int row=2;row<=hlen;row+=2){  //偶数行
            for(int i=1;i<=len;i++){
                ch[row][i] = B;
            }
            for(int i=1;i<=row/2;i++){
                ch[row][2*i-1] = A;
                ch[row][len-2*i+2] = A;
            }
        }
        if(hlen>=3){                        //奇数行
            for(int row=3;row<=hlen;row+=2){
                for(int i=1;i<=len;i++){
                    ch[row][i] = A;
                }
                for(int i=1;i<=(row-1)/2;i++){
                    ch[row][2*i] = B;
                    ch[row][len+1-2*i] = B;
                }
            }
        }
        for(int row=1;row<=hlen;row++){
            for(int col=1;col<=len;col++){
                cout<<ch[row][col];
            }
            cout<<endl;
        }
        for(int row=hlen+1;row<=len;row++){
            for(int col=1;col<=len;col++){
                cout<<ch[2*hlen-row][col];
            }
            cout<<endl;
        }
    }
    return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值