蒜頭君有一塊數碼管顯示屏,只能顯示數字。每個數字的顯示如下。每
給這道題跪了,注意數據的存儲,和訪問。具體解釋 看代碼註釋
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;
char pic[10][5][2]=
{
// 第1行 第2行 第3行 第4行 第5行(1,3,5行,也就是日字的三橫只有一筆,所以pic[1~10][{1,3,5}][1]=' ')
{{'-',' '},{'|','|'},{' ',' '},{'|','|'},{'-',' '}},//數字0的第一行,第二行,第三行……
{{' ',' '},{' ','|'},{' ',' '},{' ','|'},{' ',' '}},//數字1的第一行,第二行,第三行……
{{'-',' '},{' ','|'},{'-',' '},{'|',' '},{'-',' '}},
{{'-',' '},{' ','|'},{'-',' '},{' ','|'},{'-',' '}},
{{' ',' '},{'|','|'},{'-',' '},{' ','|'},{' ',' '}},
{{'-',' '},{'|',' '},{'-',' '},{' ','|'},{'-',' '}},
{{'-',' '},{'|',' '},{'-',' '},{'|','|'},{'-',' '}},
{{'-',' '},{' ','|'},{' ',' '},{' ','|'},{' ',' '}},
{{'-',' '},{'|','|'},{'-',' '},{'|','|'},{'-',' '}},
{{'-',' '},{'|','|'},{'-',' '},{' ','|'},{'-',' '}}
};
int main()
{
int ex,cnt=0,num[10];
char str[100];cin>>ex;getchar();
/*while(scanf("%c",&ch)==1&&ch!=10)
{
num[cnt]=ch-'0';
cnt++;
}*/
cin>>str;
for(int i=0;str[i]!='\0';i++)
num[i]=str[i]-'0';
cnt = strlen(str);
for(int row=1;row<=5;row++)//日字一共有5行
{
if(row%2==1)//日字的三橫
{
for(int i=0;i<cnt;i++)//數字
{
cout<<" ";
for(int j=0;j<ex;j++)//放大的倍數
cout<<pic[num[i]][row-1][0];
cout<<" ";
if(i!=cnt-1)
cout<<" ";
}
cout<<endl;
}else{
for(int i=0;i<ex;i++)//'|'放大的倍數
{
for(int j=0;j<cnt;j++)//數字
{
char a,b;
a=pic[num[j]][row-1][0];
b=pic[num[j]][row-1][1];
cout<<a;
for(int k=0;k<ex;k++)
cout<<" ";
cout<<b;
if(j!=cnt-1)
cout<<" ";
}
cout<<endl;
}
}
}
return 0;
}