问题 CI: 叠筐

题目描述

把一个个大小差一圈的筐叠上去,使得从上往下看时,边筐花色交错。这个工作现在要让计算机来完成,得看你的了。

输入

输入是一个个的三元组,分别是,外筐尺寸n(n为满足0<n<80的奇整数),中心花色字符,外筐花色字符,后二者都为ASCII可见字符;

输出

输出叠在一起的筐图案,中心花色与外筐花色字符从内层起交错相叠,多筐相叠时,最外筐的角总是被打磨掉。叠筐与叠筐之间应有一行间隔。

样例输入 Copy

5 ^ !
7 ( )
0

样例输出 Copy

 ^^^ 
^!!!^
^!^!^
^!!!^
 ^^^ 

 ))))) 
)((((()
)()))()
)()()()
)()))()
)((((()
 ))))) 

代码

#include <stdio.h>
int main() {
    int buf[82][82];
    int n,i,j,k;
    char a,b;
    bool firstCase = true;
    while(scanf("%d %c %c",&n,&a,&b)!=EOF) {
        if(firstCase)
            firstCase = false;
        else
            printf("\n");
        for(i=1,j=1;i<=n;i+=2,j++) {
            int x = n/2+1,y=x;
            x -= j - 1;
            y -= j - 1;
            char c = (j % 2 == 1 ? a : b);
            for(k=1;k<=i;k++) {
                buf[x][y+k-1] = c;
                buf[x+k-1][y] = c;
                buf[x+i-1][y+k-1] = c;
                buf[x+k-1][y+i-1] = c;
            }
        }
        if(n!=1) {
            buf[1][1] = ' ';
            buf[1][n] = ' ';
            buf[n][1] = ' ';
            buf[n][n] = ' ';
        }
        for(i=1;i<=n;i++) {
            for(j=1;j<=n;j++) 
                printf("%c",buf[i][j]);
            printf("\n");
        }
    }
    return 0;
}
# include<iostream>
# include<string>
# include<vector>
# include<algorithm>
# include<cmath>
# include<cstdio>
# include<map>
using namespace std;
 
char a[81][81];
 
void  setHorizontalLine(int fix, int start, int end, char content) {
    for (int i = start; i <= end; i++) {
        a[i][fix] = content;
    }
}
 
void  setVerticalLine(int fix, int start, int end, char content) {
    for (int i = start; i <= end; i++) {
        a[fix][i] = content;
    }
}
 
void eraseVex(int n) {
    a[1][1] = ' ';
    a[1][n] = ' ';
    a[n][1] = ' ';
    a[n][n] = ' ';
 
}
 
bool isFirst = true;
 
int main() {
 
    int n; // 外框尺寸
    char in, out;
    while(cin >> n >> in >> out) {
        a[81][81] = {' '};
        if(n == 1 ) {
            a[1][1] = in;
        } else {
            int center = (n + 1) / 2;
            a[center][center] = in;
            for (int i = 1 ; i <= n / 2; i++) {  //第一层 到 第五层
                int length = i * 2 + 1;
                char content = in;
                if (i % 2 == 1) {
                    content = out;
                }
 
                //左右侧
                setHorizontalLine( center - i, center - i, center + i, content);
                setHorizontalLine( center + i, center - i, center + i, content);
                // 上下册
                setVerticalLine( center + i, center - i, center + i, content);
                setVerticalLine( center - i, center - i, center + i, content);
 
 
            }
 
            eraseVex(n);
        }
 
 
        if (isFirst) {
            for (int i = 1; i <= n; i ++) {
                for (int j = 1 ; j <= n ; j++) {
                    cout << a[i][j];
                }
                cout << endl;
            }
            isFirst = false;
        } else {
            cout<<endl;
            for (int i = 1; i <= n; i ++) {
                for (int j = 1 ; j <= n ; j++) {
                    cout << a[i][j];
                }
                cout << endl;
            }
 
        }
    }
}

https://blog.youkuaiyun.com/weixin_42429718/article/details/95323347

--.. .... .- .. -.-- .- --- ---... -... . -. .-- . -. -.. ..- .. .--- .. -. -.-- .. -. .. .- -. -.-- .. .-.. .- .. --..-- --.. .- .. -... ..- -- . -. ..-. . .. --. ..- -.-- ..- .- -. --- -.. --. ..- .- -. .-.. .. --.. .... --- -. --. -.-. .... ..- -..- .. .- -. -.. . --.. .... ..- -.. --- -. --. --. ..- .- -. .-.. .. .--- .. .... ..- .- .-- .- .. .-.. .. --.. .... .. -.. . -. --. ... .... ..- .--- ..- .--- .. -. -..- .. -. --. --.. .... . -. --. .-.. .. .... . ..-. ..- .--. .- -. --..-- - .. .-.. .. .- -. -.-. .... ..- --- -.. --.. .... .- --- .--. .. -. .... . --. ..- .- -. .-.. .. --.. .... --- -. --. -.. . .--- .. -. --. -.-- .- -. .--- .. .- --- -..- ..- -. --..-- --.. .... .. -.. .- --- .-- --- -- . -. --.. .- .. -..- ..- .- -. -.-- --- -. --. -.-- ..- .-.. .. ..- -.. . -. --. --. . .... ..- .- -. .--- .. . -.. . --. .- .. .--- .. -. --..-- -.-- --- ..- --.- .. --.. .- .. --.. --- -. --. .... . -- .. .- -. ... .... .. .... ..- .- -. .--- .. . -..- ..- -.-- .- --- --.- .. .- -. --. .... ..- .- -.-- .. -..- .. . -- .. .- -. ... .... .. -.-- .- --- ... ..- --..-- -.-. .... .. -..- ..- -.-- --- ..- .... ..- .- -- .. .- -. ... .... .. .... ..- .- -. .--- .. . -.. . -... .. .- --- --.. .... ..- -. .... . --. ..- .- -. .-.. .. --. ..- --- -.-. .... . -. --. --.. .... --- -. --. -.-. .... .- -.-- .. .... ..- .- -.. . --. ..- .- -. .-.. .. ..-. .- -. --. .- -. --..-- - .. ... .... . -. --. --- -.. -.. . -.-- --- ..- -..- .. .- --- .-.. .. ..- -.-. ..- -. .-.. ...- .-.-.- --.. .... . -. --. .-- . -.翻译一下
最新发布
07-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值