请实现这么一个函数:传入一个int值,在屏幕输出类似LED显示屏效果的字母拼图,例如:
输入1234567890 提示:请注意每个字符的固定宽度和高度,两个数字间保留一个空格。
函数签名:void LEDprint(int num); void LEDprint(int num)
{
char NumDraw[10][7][7] = {
{" --- ", " | |", " | |", " | |", " | |", " | |", " --- "},
{" ", " |", " |", " |", " |", " |", " "},
{" --- ", " |", " |", " --- ", " | ", " | ", " --- "},
{" --- ", " |", " |", " --- ", " |", " |", " --- "},
{" ", " | |", " | |", " --- ", " |", " |", " "},
{" --- ", " | ", " | ", " --- ", " |", " |", " --- "},
{" --- ", " | ", " | ", " --- ", " | |", " | |", " --- "},
{" --- ", " |", " |", " |", " |", " |", " "},
{" --- ", " | |", " | |", " |---|", " | |", " | |", " --- "},
{" --- ", " | |", " | |", " ---|", " |", " |", " --- "},};
char buf[15];
memset(buf, 0, sizeof(buf));
sprintf(buf, "%d", num);
string strNum = buf;
for (int i=0; i<7; i++)
{
int j=0;
while(j < strNum.length())
{
cout<<NumDraw[strNum[j]-'0'][i];
j++;
}
cout<<endl;
}
}
int main(void)
{
cout<<"请输入数字:"<<endl;
int num;
cin>>num;
cout<<"打印如下:"<<endl;
LEDprint(num);
return 0;
}
#endif
void LEDprint(int num)
{
char NumDraw[10][7][7] = {
{" --- ", " | |", " | |", " | |", " | |", " | |", " --- "},
{" ", " |", " |", " |", " |", " |", " "},
{" --- ", " |", " |", " --- ", " | ", " | ", " --- "},
{" --- ", " |", " |", " --- ", " |", " |", " --- "},
{" ", " | |", " | |", " --- ", " |", " |", " "},
{" --- ", " | ", " | ", " --- ", " |", " |", " --- "},
{" --- ", " | ", " | ", " --- ", " | |", " | |", " --- "},
{" --- ", " |", " |", " |", " |", " |", " "},
{" --- ", " | |", " | |", " |---|", " | |", " | |", " --- "},
{" --- ", " | |", " | |", " ---|", " |", " |", " --- "},};
char buf[15];
memset(buf, 0, sizeof(buf));
sprintf(buf, "%d", num);
string strNum = buf;
for (int i=0; i<7; i++)
{
int j=0;
while(j < strNum.length())
{
cout<<NumDraw[strNum[j]-'0'][i];
j++;
}
cout<<endl;
}
}
int main(void)
{
cout<<"请输入数字:"<<endl;
int num;
cin>>num;
cout<<"打印如下:"<<endl;
LEDprint(num);
return 0;
}
#endif