hdu2074叠筐解题报告---图形打印(字符串模拟)

版权声明:转载请注明出处:https://blog.csdn.net/qq1013459920 https://blog.csdn.net/qq1013459920/article/details/84138913

                                                      叠筐

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 26089    Accepted Submission(s): 6885

Problem Description

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

Input

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

Output

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

思路:一道有点坑的水题

题目大意很简单,就是用两种字符围绕最中间的框符叠筐

通过最中间筐符位置的奇偶性来控制每行每列筐的符号,达到无论从哪个方向看向中心都是交替的效果(仔细看看图就明白了)。

WA和PE了很久,三个坑点:

1.n = 1时,直接打印内框字符

2.两个框之间才存在空行,如果后续没有框输入了,则没有空行

3.框的四个角均是空格。

AC Code:

#include<iostream>
#include<sstream>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<list>
#define mod 998244353
#define INF 0x3f3f3f3f
#define Min 0xc0c0c0c0
#define mst(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
int main(){
    int n;
    char c1, c2;
    bool ff = false;
    while(scanf("%d", &n) != EOF){
        getchar();
        scanf("%c", &c1);
        getchar();
        scanf("%c", &c2);
        if(ff) printf("\n");
        if(n == 1){
            printf("%c\n", c1);
            continue;
        }
        bool flag = false;
        if((n + 1) / 2 % 2) flag = true;
        if(flag){
           printf(" ");
            for(int j = 2; j < n; j++){
                printf("%c", c1);
            }
            printf(" ");
            printf("\n");
            for(int i = 2; i < n; i++){
                if(i <= (n + 1) / 2){
                    for(int j = 1; j <= n; j++){
                        if(j <= i || j >= n - i + 1){
                            if(j % 2) printf("%c", c1);
                            else printf("%c", c2);
                        }
                        else {
                            if(i % 2) printf("%c", c1);
                            else printf("%c", c2);
                        }
                    }
                    printf("\n");
                }
                else{
                    for(int j = 1; j <= n; j++){
                        if(j <= n - i + 1 || j >= i){
                            if(j % 2) printf("%c", c1);
                            else printf("%c", c2);
                        }
                        else {
                            if(i % 2) printf("%c", c1);
                            else printf("%c", c2);
                        }
                    }
                    printf("\n");
                }
            }
            printf(" ");
            for(int j = 2; j < n; j++){
                printf("%c", c1);
            }
            printf(" ");
        }
        else{
            printf(" ");
            for(int j = 2; j < n; j++){
                printf("%c", c2);
            }
            printf(" ");
            printf("\n");
            for(int i = 2; i < n; i++){
                if(i <= (n + 1) / 2){
                    for(int j = 1; j <= n; j++){
                        if(j <= i || j >= n - i + 1){
                            if(j % 2) printf("%c", c2);
                            else printf("%c", c1);
                        }
                        else {
                            if(i % 2) printf("%c", c2);
                            else printf("%c", c1);
                        }
                    }
                    printf("\n");
                }
                else{
                    for(int j = 1; j <= n; j++){
                        if(j <= n - i + 1 || j >= i){
                            if(j % 2) printf("%c", c2);
                            else printf("%c", c1);
                        }
                        else {
                            if(i % 2) printf("%c", c2);
                            else printf("%c", c1);
                        }
                    }
                    printf("\n");
                }
            }
            printf(" ");
            for(int j = 2; j < n; j++){
                printf("%c", c2);
            }
            printf(" ");
        }
        printf("\n");
        ff = true;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq1013459920/article/details/84138913
今日推荐