PTA qls学画图

这一天qls在学校综合楼等电梯的时候看到了电梯数字的样子,突然觉得这样写数字特别有趣,于是自己想用程序跑出来。由于正常大小输出数字太小了,qls决定加大难度,他想画出不同大小的数字,你能帮他解决这个问题吗?

输入格式:

第一行输入一个数字n表示数字的大小(具体大小解释见样例解释)。(3≤n≤10)

第二行输入一串只含数字的字符串。(字符串长度不超过20)

输出格式:

输出字符串的图像,每两个数字图像之间有一个空格(具体解释见样例解释)。

样例1

样例输入
3
123
样例输出
  * *** ***
  *   *   *
  * *** ***
  * *     *
  * *** ***

样例2

样例输入
4
567
样例输出
**** **** ****
*    *       *
*    *       *
**** ****    *
   * *  *    *
   * *  *    *
**** ****    *

提示

数字按照电梯样式并用字符‘*’表示边,大小的定义是在一个n×(2n−1)的长方形表示数字,每两个数字之间用空格间隔。

例如大小为3的0到9样式如下:

5e0e70f470.png

代码长度限制

16 KB

时间限制

1000 ms

内存限制

256 MB

栈限制

8192 KB

纯模拟,没有别的,注意细节就行

#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define PII pair<int,int>
#define fi first
#define pb push_back
#define sec second
#define endl '\n'
#define INF 0x3f3f3f3f
const int N=2e5+10;
const int M=1e6+10;
int n,m,k,T;
void draw(int x,int y  ){
	int a ;
	if(y==1){
		if(x==1){
			a=n-1;
			while(a--){
				cout << " ";
			}
			cout << "*";
		}else if(x==2||x==3||x==0||x==5||x==6||x==7||x==8||x==9){
			a=n;
			while(a--){
				cout << '*';
			}
		}else{
			cout << '*';
			a=n-2;
			while(a--)cout << ' ';
			cout << "*";
		}
	}else if(y==m){
		if(x==0||x==2||x==3||x==5||x==6||x==8||x==9){
			a=n;
			while(a--){
				cout << '*';
			}
		}else if(x==1||x==4||x==7){
			a=n-1;
			while(a--)cout << ' ';
			cout << "*";
		}else{
			
		}
	}else if(y==m/2+1){
		if(x==2||x==3||x==4||x==5||x==6||x==8||x==9){
			a=n;
			while(a--){
				cout << '*';
			}
		}else if(x==0){
			cout << '*';
			a=n-2;
			while(a--)cout << ' ';
			cout << "*";
		}else if(x==1||x==7){
			a=n-1;
			while(a--)cout << ' ';
			cout << '*';
		}
	}else if(y<m/2+1){
		if(x==0||x==4||x==8||x==9){
			a=n-2;
			cout << '*';
			while(a--)cout << ' ';
			cout << '*';
		}else if(x==1||x==2||x==3||x==7){
			a=n-1;
			while(a--)cout << ' ';
			cout << '*';
		}else{
			a=n-1;
			cout << '*';
			while(a--)cout << ' ';
		}
	}else{
		if(x==0||x==6||x==8){
			a=n-2;
			cout << '*';
			while(a--)cout << ' ';
			cout << '*';
		}else if(x==1||x==3||x==4||x==5||x==7||x==9){
			a=n-1;
			while(a--)cout << ' ';
			cout << '*';
		}else{
			cout << '*';
			a=n-1;
			while(a--)cout << ' ';
		}
	}
} 
signed main(){
	cin >> n ;
	string s ;
	cin >> s ;
	m=2*n-1;
	for(int j=1;j<=m;j++){
		for(int i=0;i<s.size();i++){
			if(i!=0)cout << ' ';
			draw(s[i]-48,j);
		}
		cout << endl;
	}
	return 0;
}

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值