题目链接:http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=1017

Description
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 ( 0n99, 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
— — —
| | | | | |
| | | | | |
— — — —
| | | | |
| | | | |
— — —

— — — — —
| | | | | | | |
| | | | | | | |
| | | | | | | |
— — —
| | | | | | | |
| | | | | | | |
| | | | | | | |
— — — —
这是其实只要按照题意一步步的打就好了,没有什么特别的想法。。做完后发现好多大牛都是用打表做的,顿时石化啊。。吾等菜鸟怎能与大牛匹敌,木有想到啊。。弱弱的写下我的代码把。。。题目复制不是很清楚,可以点击链接查看原题。。

code:

#include”stdio.h”
#include”string.h”
int main()
{
int s,i,j,k;
char str[10];
while(scanf(“%d%s”,&s,str)!=EOF)
{
if(s==0&&str[0]==’0′)
break;
for(i=1;i<=2*s+3;i++)
{
for(j=0;str[j]!='';j++)
{
for(k=1;k1&&is+2&&i<2*s+3)
{
if((str[j]=='1'||str[j]=='3'||str[j]=='4'||str[j]=='5'||str[j]=='7'||str[j]=='9')&&k==s+2)
printf("|");
else if(str[j]=='2'&&k==1)
printf("|");
else if((str[j]=='6'||str[j]=='8'||str[j]=='0')&&(k==1||k==s+2))
printf("|");
else
printf(" ");
}//中部一下最后一行以上部分
if(i==2*s+3)
{
if(str[j]=='1'||str[j]=='4'||str[j]=='7')
printf(" ");
else if(k==1||k==s+2)
printf(" ");
else
printf("-");
}//最后一行
}
if(str[j+1]!=0)
printf(" ");
}
printf("\n");
if(i==2*s+3)
printf("\n");
}
}
return 0;
}

菜鸟之作,仅供参考,如有错误,请您指出。——Tamara

发表评论

电子邮件地址不会被公开。

Post Navigation