Description
A friend of you has just bought a new computer. Until now, the most powerful computer he ever used has been a pocket calculator. Now, looking at his new computer, he is a bit disappointed, because he liked the LC-display of his calculator so much. So you decide to write a program that displays numbers in an LC-display-like style on his computer.
Input
The input contains several lines, on
e for each number to be displayed. Each line contains two integers s, n (1 <= s <= 10, 0 <= n <= 99 999 999), where n is the number to be displayed and s is the size in which it shall be displayed.
The input file will be terminated by a line containing two zeros. This line should not be processed.
The input file will be terminated by a line containing two zeros. This line should not be processed.
Output
Output the numbers given in the input file in an LC-display-style using s "-" signs for the horizontal segments and s "|" signs for the vertical on
es. Each digit occupies exactly s+2 columns and 2s+3 rows. (Be sure to fill all the white space occupied by the digits with blanks, also for the last digit.) There has to be exactly on
e column of blanks between two digits.
Output a blank line after each number. (You will find a sample of each digit in the sample output.)
Output a blank line after each number. (You will find a sample of each digit in the sample output.)
Sample Input
2 12345 3 67890 0 0
Sample Output
-- -- -- | | | | | | | | | | | | -- -- -- -- | | | | | | | | | | -- -- -- --- --- --- --- --- | | | | | | | | | | | | | | | | | | | | | | | | --- --- --- | | | | | | | | | | | | | | | | | | | | | | | | --- --- --- ---
Source
看看sample input和sample output就知道它让你干嘛了……所以一行行暴力一点的输出就好
#include<stdio.h>
#include<string.h>
void row_0(int n){int i;for(i=1;i<=n+2;i++) printf(" ");}
void row_1(int n){int i;printf(" ");for(i=1;i<=n;i++) printf("-");printf(" ");}
void col_l(int n){int i;printf("|");for(i=1;i<=n+1;i++) printf(" ");}
void col_r(int n){int i;for(i=1;i<=n+1;i++) printf(" ");printf("|");}
void col_b(int n){int i;printf("|");for(i=1;i<=n;i++) printf(" ");printf("|");}
void display(int num[],int n)
{
int r,c,i;
for(r=1;r<=2*n+3;r++){
//输出三个衡横行
if((r-1)%(n+1)==0)
for(c=0;num[c]>=0;c++){
if(num[c]==2 || num[c]==3 || num[c]==5 || num[c]==6 || num[c]==8 || num[c]==9) row_1(n);
if(num[c]==1) for(i=1;i<=n+2;i++) printf(" ");
if(num[c]==4){
if((r-1)/(n+1)==1) row_1(n);
else row_0(n);
}
if(num[c]==7){
if((r-1)/(n+1)==0) row_1(n);
else row_0(n);
}
if(num[c]==0){
if((r-1)/(n+1)==1) row_0(n);
else row_1(n);
}
printf(" ");
}
//输出上竖行
if(r>1 && r<n+2)
for(c=0;num[c]>=0;c++){
if(num[c]==5 || num[c]==6) col_l(n);
if(num[c]==1 || num[c]==2 || num[c]==3 || num[c]==7) col_r(n);
if(num[c]==4 || num[c]==8 || num[c]==9 || num[c]==0) col_b(n);
printf(" ");
}
//输出下竖行
if(r>n+2 && r<2*n+3)
for(c=0;num[c]>=0;c++){
if(num[c]==2) col_l(n);
else if(num[c]==0 || num[c]==6 || num[c]==8) col_b(n);
else col_r(n);
printf(" ");
}
printf("\n");
}
}
int main()
{
int i,n,num[9];char temp[9];
while( scanf("%d %s",&n,&temp) && n!=0 ){
memset(num,-1,sizeof(num));
for(i=0;temp[i];i++){
num[i]=temp[i]-'0';
}
display(num,n);
if(n!=0) printf("\n");
}
}