Problem N: 七段显示器显示整数

Problem Description

编写程序,输入一个整数,使用字符模拟七段显示器来输出该数。
计算器、电子手表和其它电子设备经常依靠七段显示器进行数值的输出。为了组成数字,这类设备需要“打开”7个显示段中的某些部分,同时“关闭”其它部分:
 


需要设置一个数组来保存显示0到9数字时需要“打开”和“关闭”的显示段。各显示段的编号如下:
 

Input Description

输入数据有多组,每组占一行,为一个不超过10位的正整数。

Output Description

对于每组输入数据,使用字符模拟七段显示器来输出该整数,每个数字之间留一个空格。

Sample Input

2020

Sample Output

 _   _   _   _  
 _| | |  _| | | 
|_  |_| |_  |_| 

#include<stdio.h>
#include <string.h>
#define MAX_DIGIT 10

const int print_nu[10][9] = {
		{7,0,7,5,7,1,4,3,2},
		{7,7,7,7,7,1,7,7,2},
		{7,0,7,7,6,1,4,3,7},
		{7,0,7,7,6,1,7,3,2},
		{7,7,7,5,6,1,7,7,2},
		{7,0,7,5,6,7,7,3,2},
		{7,0,7,5,6,7,4,3,2},
		{7,0,7,7,7,1,7,7,2},
		{7,0,7,5,6,1,4,3,2},
		{7,0,7,5,6,1,7,3,2}
};
int nums[MAX_DIGIT];
void printf_char(int ch1);
void show_char(char *ch, int temp);

int main()
{
	char ch[10];
	int cnt = 0;
	int temp = 0;

	while (scanf("%s", &ch) != EOF)
	{
		temp = strlen(ch);
		for (int a = 0; a < temp; a++)
		{
			if (cnt < 10 && ch[a] >= '0' && ch[a] <= '9' && ch[a] != '\n')
				nums[a] = ch[a] - '0';
			else
				break;
		}
		show_char(ch, temp);

	}


}

void show_char(char *ch, int temp)
{
	int i = 0, j = 0;
	for (i = 0; i < 3; i++)
	{
		for (int ten = 0; ten < temp; ten++)
		{
			for (j = i * 3; j < 3 * (i + 1); j++)
			{
				int n = nums[ten];
				printf_char(print_nu[n][j]);
			}
			printf(" ");
		}
		printf("\n");
	}
}

void printf_char(int ch1) {

	switch (ch1) {
	case 0:
		printf("_");
		break;
	case 1:
		printf("|");
		break;
	case 2:
		printf("|");
		break;
	case 3:
		printf("_");
		break;
	case 4:
		printf("|");
		break;
	case 5:
		printf("|");
		break;
	case 6:
		printf("_");
		break;
	case 7:
		printf(" ");
		break;

	}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值