快速提升代码能力(13)getchar();

从零起步看算法(第十三天  4.18)

//q14 显示屏输出

1.二维数组的模拟问题,大概是软肋了,三维数组的基本使用

大神做法:https://blog.csdn.net/liukairui/article/details/79409329

2.大数输入用字符

3.空格如何输出,理解二维数组的真实实现过程

4.细节问题的处理。循环多,思路不能乱

5.全场最佳:getchar();

本题简单理解为,输入int 和char时 清楚缓存区

详细用法:https://blog.csdn.net/gsd4_chenmeng/article/details/73409887

AC代码:

//q14显示屏输出
#include<iostream> 
#include<cstdio>
#include<string>
#include<algorithm>
#include<assert.h>
using namespace std;
char pic[10][5][2]={
{{'-',' '},{'|','|'},{' ',' '},{'|','|'},{'-',' '}},
{{' ',' '},{' ','|'},{' ',' '},{' ','|'},{' ',' '}},
{{'-',' '},{' ','|'},{'-',' '},{'|',' '},{'-',' '}},
{{'-',' '},{' ','|'},{'-',' '},{' ','|'},{'-',' '}},
{{' ',' '},{'|','|'},{'-',' '},{' ','|'},{' ',' '}},
{{'-',' '},{'|',' '},{'-',' '},{' ','|'},{'-',' '}},
{{'-',' '},{'|',' '},{'-',' '},{'|','|'},{'-',' '}},
{{'-',' '},{' ','|'},{' ',' '},{' ','|'},{' ',' '}},
{{'-',' '},{'|','|'},{'-',' '},{'|','|'},{'-',' '}},
{{'-',' '},{'|','|'},{'-',' '},{' ','|'},{'-',' '}}
};
int main(){
	int k;
	int cnt=0;
	char buf;
	int n[10];//n<1000000
	cin>>k;
    getchar();
	while(scanf("%c",&buf)==1&&buf!=10){//录入字符进数组 
		n[cnt]=buf-'0';
		cnt++;
	}
	for(int m=1;m<=5;m++){//一行一行输出
	
	          if(m%2==1){//打印"---"
	                for(int j=0;j<cnt;j++){
	                	cout<<" ";//初始空格 
	                 for(int i=0;i<k;i++){//第几个数的第m行 
		                 cout<<pic[n[j]][m-1][0];
	                                     } 
	                    cout<<" ";
	                    if(j!=cnt-1){
	                    	cout<<" ";//末尾无空格 
						} 
	                    }
						cout<<endl;//所有数的第1.3.5行打印 
	                }
	            else{
	            	for(int h=0;h<k;h++){//竖向扩展
					    for(int j=0;j<cnt;j++){
					    	char a,b;//考虑到空格
							a=pic[n[j]][m-1][0];
							b=pic[n[j]][m-1][1];
							cout<<a;
							for(int p=0;p<k;p++){
								cout<<" ";
							} 
							cout<<b;
							if(j!=cnt-1){
								cout<<" "; 
							}
						}
							cout<<endl;	
					}
				} 
	} 
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值