思路&题解

PC/UVA 110104/704
本题。只需要模拟即可

//author: CHC
//First Edit Time: 2014-01-11 12:58
//Last Edit Time: 2014-01-11 13:47
//Filename:1.cpp
#include <iostream>
#include <cstdio>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
int s,n,len;
char temp[1000];
char tt[]="---------------------------------";
void print(int i)
{
for(int j=0;j<len;j++)
{
int num=temp[j]-'0';
if(num==0)
{
if(i==0)
printf("%*s",s+2,"");
else if(abs(i)!=s+1)
printf("|%*s|",s,"");
else
printf(" %.*s ",s,tt);
}
else if(num==1)
{
if(abs(i)!=s+1&&i!=0) printf("%*s",s+2,"|");
else printf("%*s",s+2,"");
}
else if(num==2)
{
if(i==0||abs(i)==s+1) printf(" %.*s ",s,tt);
else if(i<0) printf("%*s|",s+1,"");
else printf("|%*s",s+1,"");
}
else if(num==3)
{
if(abs(i)==s+1||i==0) printf(" %.*s ",s,tt);
else printf("%*s",s+2,"|");
}
else if(num==4)
{
if(abs(i)==s+1)printf("%*s",s+2,"");
else if(i==0)printf(" %.*s ",s,tt);
else if(i<0)printf("|%*s|",s,"");
else printf("%*s",s+2,"|");
}
else if(num==5)
{
if(abs(i)==s+1||i==0)printf(" %.*s ",s,tt);
else if(i<0)printf("|%*s",s+1,"");
else if(i>0)printf("%*s|",s+1,"");
}
else if(num==6)
{
if(abs(i)==s+1||i==0)printf(" %.*s ",s,tt);
else if(i<0)printf("|%*s",s+1,"");
else printf("|%*s|",s,"");
}
else if(num==7)
{
if(i==-s-1)printf(" %.*s ",s,tt);
else if(i==0||i==s+1)printf("%*s",s+2,"");
else printf("%*s|",s+1,"");
}
else if(num==8)
{
if(abs(i)==s+1||i==0) printf(" %.*s ",s,tt);
else printf("|%*s|",s,"");
}
else if(num==9)
{
if(abs(i)==s+1||i==0)printf(" %.*s ",s,tt);
else if(i<0)printf("|%*s|",s,"");
else printf("%*s",s+2,"|");
}
if(j!=len-1)putchar(' ');
}
}
int main()
{
while(~scanf("%d%d",&s,&n)&&(s||n))
{
sprintf(temp,"%d",n);
len=strlen(temp);
for(int i=-s-1;i<=s+1;i++,puts(""))
{
print(i);
}
puts("");
}
return 0;
}

LC-Display

A friend of yours has just bought a new computer. Before this, the most powerful machine he ever used was a pocket calculator. He is a little disappointed because he liked the LCD display of his calculator more than the screen on his new computer! To make him happy, write a program that prints numbers in LCD display style.

Input

The input file contains several lines, one for each number to be displayed. Each line contains integers s and n, where n is the number to be displayed ( 0 < n < 99, 999, 999) and s is the size in which it shall be displayed ( 1s10).
The input will be terminated by a line containing two zeros, which should not be processed.

Output

Print the numbers specified in the input file in an LCD display-style using s ‘-’ signs for the horizontal segments and s ‘|’ signs for the vertical ones. 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, including the last digit. There must be exactly one column of blanks between two digits. Output a blank line after each number. You will find an example of each digit in the sample output below.

Sample Input

2 12345  
3 67890  
0 0  

Sample Output

      --   --        --  
   |    |    | |  | |  
   |    |    | |  | |  
      --   --   --   --  
   | |       |    |    |  
   | |       |    |    |  
      --   --        --  

 ---   ---   ---   ---   ---  
|         | |   | |   | |   |  
|         | |   | |   | |   |  
|         | |   | |   | |   |  
 ---         ---   ---  
|   |     | |   |     | |   |  
|   |     | |   |     | |   |  
|   |     | |   |     | |   |  
 ---         ---   ---   ---