LC-Display

LC-Display

时间: 1ms        内存:64M

描述:

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.

输入:

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

输出:

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.

示例输入:

2 12345
3 67890
0 0

示例输出:

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

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

提示:

参考答案(内存最优[752]):

#include"stdio.h"
#include"string.h"
int a[10][7]={{1,1,1,0,1,1,1},{0,0,1,0,0,1,0},{1,0,1,1,1,0,1},{1,0,1,1,0,1,1},{0,1,1,1,0,1,0},{1,1,0,1,0,1,1},{1,1,0,1,1,1,1},{1,0,1,0,0,1,0},{1,1,1,1,1,1,1},{1,1,1,1,0,1,1}};
int main()
{
	int n,i,j,k,length,b[12];
	char s[12];
	while(1)
	{
		scanf("%d %s",&n,s);
		if(!n&&s[0]=='0')break;
		length=strlen(s);
		for(i=0;i<length;i++)
		{
			b[i]=s[i]-'0';
		}
		for(i=0;i<length;i++)
		{
			printf(" ");
			for(j=0;j<n;j++)
			{
				if(a[b[i]][0])printf("-");
				else printf(" ");
			}
			printf(" ");
			if(i!=length-1)printf(" ");
		}
		printf("\n");
		for(i=0;i<n;i++)
		{
			for(j=0;j<length;j++)
			{
				if(a[b[j]][1])printf("|");
				else printf(" ");
				for(k=0;k<n;k++)
				printf(" ");
				if(a[b[j]][2])printf("|");
				else printf(" ");
				if(j!=length-1)printf(" ");
			}
			printf("\n");
		}
		
		for(i=0;i<length;i++)
		{
			printf(" ");
			for(j=0;j<n;j++)
			{
				if(a[b[i]][3])printf("-");
				else printf(" ");
			}
			printf(" ");
			if(i!=length-1)printf(" ");
		}
		printf("\n");
		for(i=0;i<n;i++)
		{
			for(j=0;j<length;j++)
			{
				if(a[b[j]][4])printf("|");
				else printf(" ");
				for(k=0;k<n;k++)
				printf(" ");
				if(a[b[j]][5])printf("|");
				else printf(" ");
				if(j!=length-1)printf(" ");
			}
			printf("\n");
		}
		
		for(i=0;i<length;i++)
		{
			printf(" ");
			for(j=0;j<n;j++)
			{
				if(a[b[i]][6])printf("-");
				else printf(" ");
			}
			printf(" ");
			if(i!=length-1)printf(" ");
		}
		printf("\n\n");
	}
	return 0;
}


参考答案(时间最优[0]):

#include"stdio.h"
#include"string.h"
int a[10][7]={{1,1,1,0,1,1,1},{0,0,1,0,0,1,0},{1,0,1,1,1,0,1},{1,0,1,1,0,1,1},{0,1,1,1,0,1,0},{1,1,0,1,0,1,1},{1,1,0,1,1,1,1},{1,0,1,0,0,1,0},{1,1,1,1,1,1,1},{1,1,1,1,0,1,1}};
int main()
{
	int n,i,j,k,length,b[12];
	char s[12];
	while(1)
	{
		scanf("%d %s",&n,s);
		if(!n&&s[0]=='0')break;
		length=strlen(s);
		for(i=0;i<length;i++)
		{
			b[i]=s[i]-'0';
		}
		for(i=0;i<length;i++)
		{
			printf(" ");
			for(j=0;j<n;j++)
			{
				if(a[b[i]][0])printf("-");
				else printf(" ");
			}
			printf(" ");
			if(i!=length-1)printf(" ");
		}
		printf("\n");
		for(i=0;i<n;i++)
		{
			for(j=0;j<length;j++)
			{
				if(a[b[j]][1])printf("|");
				else printf(" ");
				for(k=0;k<n;k++)
				printf(" ");
				if(a[b[j]][2])printf("|");
				else printf(" ");
				if(j!=length-1)printf(" ");
			}
			printf("\n");
		}
		
		for(i=0;i<length;i++)
		{
			printf(" ");
			for(j=0;j<n;j++)
			{
				if(a[b[i]][3])printf("-");
				else printf(" ");
			}
			printf(" ");
			if(i!=length-1)printf(" ");
		}
		printf("\n");
		for(i=0;i<n;i++)
		{
			for(j=0;j<length;j++)
			{
				if(a[b[j]][4])printf("|");
				else printf(" ");
				for(k=0;k<n;k++)
				printf(" ");
				if(a[b[j]][5])printf("|");
				else printf(" ");
				if(j!=length-1)printf(" ");
			}
			printf("\n");
		}
		
		for(i=0;i<length;i++)
		{
			printf(" ");
			for(j=0;j<n;j++)
			{
				if(a[b[i]][6])printf("-");
				else printf(" ");
			}
			printf(" ");
			if(i!=length-1)printf(" ");
		}
		printf("\n\n");
	}
	return 0;
}


题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注