题目:http://poj.org/problem?id=1102
LC-Display
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 15752 | Accepted: 6291 |
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, one 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 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, also for the last digit.) There has to be exactly one 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
-- -- -- | | | | | | | | | | | | -- -- -- -- | | | | | | | | | | -- -- -- --- --- --- --- --- | | | | | | | | | | | | | | | | | | | | | | | | --- --- --- | | | | | | | | | | | | | | | | | | | | | | | | --- --- --- ---分析:是的,这就是一道模拟题,仅此而已。需要细心。我是先把8按照尺寸要求写出来,然后其他数字再在8的基础上抹去某些笔画,再保存该数字。
解题时我干了一件用时间换空间的傻事,n<1e9的,顶多8位数,我神乎其神的误认为保存结果的话需要1e9的数组空间,||-_- 是一维为9的空间!下面的代码数组直接二维,没有保存所有的数字信息,写出一个数字print一部分,这时间浪费的啊。。还好过了。。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int s;
char n[20],eight[35][20],str[35][20];
void printblank(){
for(int i=0;i<2*s+3;i++) printf(" \n");
}
void createight(){
memset(eight,0,sizeof(eight));
eight[0][0]=' '; for(int j=1;j<s+1;j++) eight[0][j]='-'; eight[0][s+1]=' ';
for(int i=1;i<s+1;i++){
eight[i][0]='|'; for(int j=1;j<s+1;j++) eight[i][j]=' '; eight[i][s+1]='|';
}
eight[s+1][0]=' '; for(int j=1;j<s+1;j++) eight[s+1][j]='-'; eight[s+1][s+1]=' ';
for(int i=s+2;i<2*s+2;i++){
eight[i][0]='|'; for(int j=1;j<s+1;j++) eight[i][j]=' '; eight[i][s+1]='|';
}
eight[2*s+2][0]=' '; for(int j=1;j<s+1;j++) eight[2*s+2][j]='-'; eight[2*s+2][s+1]=' ';
}
void clear(int p){
if(p==1) for(int j=0;j<s+2;j++) str[0][j]=' ';
else if(p==2) for(int i=1;i<s+1;i++) str[i][0]=' ';
else if(p==3) for(int i=1;i<s+1;i++) str[i][s+1]=' ';
else if(p==4) for(int j=0;j<s+2;j++) str[s+1][j]=' ';
else if(p==5) for(int i=s+2;i<2*s+2;i++) str[i][0]=' ';
else if(p==6) for(int i=s+2;i<2*s+2;i++) str[i][s+1]=' ';
else if(p==7) for(int j=0;j<s+2;j++) str[2*s+2][j]=' ';
}
void copy(){
for(int i=0;i<2*s+3;i++){
for(int j=0;j<s+2;j++) str[i][j]=eight[i][j];
}
}
void print(int x){
copy();
if(x==1){ clear(1); clear(2); clear(4); clear(5); clear(7); }
else if(x==2){ clear(2); clear(6); }
else if(x==3){ clear(2); clear(5); }
else if(x==4){ clear(1); clear(5); clear(7); }
else if(x==5){ clear(3); clear(5); }
else if(x==6){ clear(3); }
else if(x==7){ clear(2); clear(4); clear(5); clear(7); }
else if(x==9){ clear(5); }
else if(x==0){ clear(4); }
}
int main()
{
//freopen("cin.txt","r",stdin);
while(cin>>s>>n){
if(s==0&&n[0]=='0') break;
createight();
int length=strlen(n);
int i,j,k;
for(i=0;i<2*s+3;i++){
for(k=0;k<length;k++){
print(n[k]-'0');
for(j=0;j<s+2;j++) printf("%c",str[i][j]);
printf(" ");
}
puts("");
}
puts("");
}
return 0;
}