luogu P1538 迎春舞会之数字舞蹈

题解

看到别人都用了什么结构来存储,我就比较简单粗暴了,直接按 行 - 字 - 列 的顺序依次考虑输出对象。
想清楚了其实不难,就是稍微繁杂了点,有点像小学奥赛题…


Code

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int n,m;
int cot[256];
void pr(int k){
    for(int j=1;j<=2*k+3;j++){// row
        for(int i=0;i<n;i++){ // each num

            for(int pos=1;pos<=k+3;pos++){ // col
                if(pos==k+3) {
                    cout<<" ";// last col space
                    break;
                }
                if(j==1){ // head
                    if( pos==1 || pos==k+2) cout<<" ";
                    else{
                        if(cot[i]==1 || cot[i]==4) cout<<" ";
                        else cout<<"-";
                    }
                }

                if( j>1 && j<k+2 ){ // up body
                    if(pos>1 && pos <k+2) cout<<" ";
                    else{
                        if(pos==1){
                            if(cot[i]==1||cot[i]==2||
                                cot[i]==3||cot[i]==7) cout<<" ";
                            else cout<<"|";
                        }else{
                            if(cot[i]==5||cot[i]==6) cout<<" ";
                            else cout<<"|";
                        }
                    }
                }

                if( j== k+2 ){// waist
                    if(pos==1||pos==k+2) cout<<" ";
                    else{
                        if(cot[i]==1||cot[i]==7||cot[i]==0) cout<<" ";
                        else cout<<"-";
                    }
                }

                if( j>k+2 && j< 2*k+3){// down body
                    if(pos>1 && pos <k+2) cout<<" ";
                    else{
                        if(pos==1){
                            if(cot[i]==2||cot[i]==6||
                                cot[i]==8||cot[i]==0) cout<<"|";
                            else cout<<" ";
                        }
                        else{
                            if(cot[i]==2) cout<<" ";
                            else cout<<"|";
                        }
                    }
                }

                if(j==2*k+3){// foot
                    if(pos==1||pos==k+2) cout<<" ";
                    else{
                        if(cot[i]==1||cot[i]==4||
                            cot[i]==7) cout<<" ";
                        else cout<<"-";
                    }
                }
            }
        }
        cout<<endl;
    }
}
int main(){

    int k;
    cin>>k;
    string str;
    cin>>str;
    n = str.size();
    for(int i=0;i<n;i++) {
        cot[i] = str[i]-'0';
    }
    pr(k);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值