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