P1538 迎春舞会之数字舞蹈

P1538 迎春舞会之数字舞蹈

依旧是~骚粉色。

值得注意的是:这道题里面说的并不是数字前要输出空格,而是数字后。

被坑在这里。

题意:给出一系列数字,和一个k值,用k大的横线或者竖线表示数字。

题解:预处理一下每个数字什么时候要输出,什么时候不要。最多只需要7条线来表示。

两种解法:第一种我的,第二种大佬的。

但是总体思想一致,只是他的比较简洁。

引用:https://www.luogu.org/problemnew/solution/P1538

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    string s,m[10]={"-|| ||-","  |  | ","- |-| -",
    "- |- |-"," ||- | ",    "-| - |-","-| -||-",
    "- |  | ","-||-||-","-||- |-"};
    cin>>k>>s;
    for (int p=0;p<7;p++){
        if (p==2 || p==5) continue;
        if (p%3==0){
            for (int i=0;i<s.size();i++){
                cout<<' ';
                for (int j=0;j<k;j++){
                    cout<<m[s[i]-48][p];
                }
                cout<<"  ";
            }
            cout<<endl;        
        }else{
            for(int q=0;q<k;q++){
                for (int i=0;i<s.size();i++){
                    cout<<m[s[i]-48][p];
                    for (int j=0;j<k;j++){
                        cout<<' ';
                    }
                    cout<<m[s[i]-48][p+1]<<' ';
                }
                cout<<endl;
            }
        }
    }
    return 0;
}

剩下是我的:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

char str[10][7]={
    {1,1,1,0,1,1,1},{0,0,1,0,0,1,0},{1,0,1,1,1,0,1},{1,0,1,1,0,1,1},
    {0,1,1,1,0,1,0},{1,1,0,1,0,1,1},{1,1,0,1,1,1,1},{1,0,1,0,0,1,0},
    {1,1,1,1,1,1,1},{1,1,1,1,0,1,1},
};

int main()
{
    string a;
    int k;
    cin>>k>>a;
    int flag;
    for(int i=0;i<2*k+3;i++)
    {
       if(i==0||i==k+1||i==2*k+2)
       {
       	    if(i==0)flag=0;
       	    if(i==k+1)flag=3;
       	    if(i==2*k+2)flag=6;
            for(int j=0;j<a.size();j++)
            {
                cout<<" ";
             if(str[a[j]-'0'][flag])
             {
                 for(int x=1;x<=k;x++)
                 {
                    cout<<"-";	
                 }
             }
             else
             {
             	 for(int x=1;x<=k;x++)
             	 {
 	             	cout<<" ";
 	             }
             }
             cout<<"  ";
            }
   	   }
   	   else if(i<k+1)
   	   {
   	   	    for(int j=0;j<a.size();j++)
   	   	    {
    	   	   	flag=1;
                if(str[a[j]-'0'][flag])
    	   	   	{
       	   	    	cout<<"|";
       	   	    }
       	   	    else cout<<" ";
       	   	    flag=2;
       	   	    for(int x=1;x<=k;x++)
       	   	    {
    	   	   		cout<<" ";
    	   	   	}
    	   	   	if(str[a[j]-'0'][flag])
    	   	   	{
       	   	    	cout<<"|";
       	   	    }
       	   	    else cout<<" ";
       	   	    cout<<" ";
   	        }
   	   }
   	   else
   	   {
 	   	    for(int j=0;j<a.size();j++)
   	   	    {
    	   	   	flag=4;
                if(str[a[j]-'0'][flag])
    	   	   	{
       	   	    	cout<<"|";
       	   	    }
       	   	    else cout<<" ";
       	   	    flag=5;
       	   	    for(int x=1;x<=k;x++)
       	   	    {
    	   	   		cout<<" ";
    	   	   	}
    	   	   	if(str[a[j]-'0'][flag])
    	   	   	{
       	   	    	cout<<"|";
       	   	    }
       	   	    else cout<<" ";
       	   	    cout<<" ";
   	        }
   	   }
   	   cout<<endl;
    }
}

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值