从零起步看算法(第十三天 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;
}