显示器
如果某行输入包括两个0,表示输入结束。这行不需要处理。
2 12345 3 67890 0 0
-- -- -- | | | | | | | | | | | | -- -- -- -- | | | | || | | | |-- -- -- --- --- --- --- --- | | | | | | | | | | | | | | | | | | | | | | | |--- --- --- | | | | | | | | | | | | | | | | | | | | | | | |--- --- --- ---
数(number)由一个或者多个数字组成。 解题思路
从输出的结果来看,它是有规律的,就是每一个输出的数的每一行只会出现5种情况
1,------ ,即一行除了开头和结尾都是‘-’;
2, ,即一行全为空格;
3,开头和结尾都为‘|’;
4,只有开头是‘|’;
5,只有结尾是‘|’;
而且5种情况出现的位置也是有规律,所以可以通过规律非常容易的写出来,。
#include<stdio.h>
#include<string.h>
void l(int s)
{int i;for(i=0;i<s+2;i++){printf(" ");}
}
void ll(int s)
{int i;for(i=0;i<s+2;i++){if(i==0||i==s+1){printf(" ");}else{printf("-");}}
}
void lll(int s)
{int i;for(i=0;i<s+2;i++){if(i==0){printf("|");}else{printf(" ");}}
}
void llll(int s)
{int i;for(i=0;i<s+2;i++){if(i==s+1){printf("|");}else{printf(" ");}}
}
void lllll(int s)
{int i;for(i=0;i<s+2;i++){if(i==0||i==s+1){printf("|");}else{printf(" ");}}
}
int main()
{int s,i,j,g;char n[99999];while(1){scanf("%d%s",&s,n);g=strlen(n);if(s==0&&n[0]=='0'&&g==1){break;}for(j=0;j<g;j++){if(n[j]=='1'||n[j]=='4'){l(s);}else{ll(s);}if(n[j+1]!='\n')printf(" ");}printf("\n");for(i=0;i<s;i++){for(j=0;j<g;j++){if(n[j]=='0'||n[j]=='9'||n[j]=='8'||n[j]=='4'){lllll(s);}if(n[j]=='1'||n[j]=='2'||n[j]=='3'||n[j]=='7'){llll(s);}if(n[j]=='5'||n[j]=='6'){lll(s);}if(n[j+1]!='\n')printf(" ");}printf("\n");}for(j=0;j<g;j++){if(n[j]=='1'||n[j]=='7'||n[j]=='0'){l(s);}else{ll(s);}if(n[j+1]!='\n')printf(" ");}printf("\n");for(i=0;i<s;i++){for(j=0;j<g;j++){if(n[j]=='0'||n[j]=='6'||n[j]=='8'){lllll(s);}if(n[j]=='7'||n[j]=='1'||n[j]=='4'||n[j]=='3'||n[j]=='5'||n[j]=='9'){llll(s);}if(n[j]=='2'){lll(s);}if(n[j+1]!='\n')printf(" ");}printf("\n");}for(j=0;j<g;j++){if(n[j]=='1'||n[j]=='4'||n[j]=='7'){l(s);}else{ll(s);}if(n[j+1]!='\n')printf(" ");}printf("\n");printf("\n");}return 0;
}