Elliot_Lin_洛谷P5730 【深基5.例10】显示屏

【深基5.例10】显示屏

题目描述

液晶屏上,每个阿拉伯数字都是可以显示成 3 × 5 3\times5 3×5 的点阵的(其中 X 表示亮点,. 表示暗点)。现在给出数字位数(不超过 100 100 100)和一串数字,要求输出这些数字在显示屏上的效果。数字的显示方式如同样例输出,注意每个数字之间都有一列间隔。

输入格式

第一行输入一个正整数 n n n,表示数字的位数。

第二行输入一个长度为 n n n 的自然数。

输出格式

输出五行,表示显示屏上的数字。

样例 #1

样例输入 #1

10
0123456789

样例输出 #1

XXX...X.XXX.XXX.X.X.XXX.XXX.XXX.XXX.XXX
X.X...X...X...X.X.X.X...X.....X.X.X.X.X
X.X...X.XXX.XXX.XXX.XXX.XXX...X.XXX.XXX
X.X...X.X.....X...X...X.X.X...X.X.X...X
XXX...X.XXX.XXX...X.XXX.XXX...X.XXX.XXX

提示

数据保证, 1 ≤ n ≤ 100 1 \leq n \leq 100 1n100

参考(vscode中对,但洛谷中WA)

输出结果与洛谷中是一样的
#include<stdio.h>
#define N 100
int main(){
    char* dot[5][10];
    // line_1
    dot[0][0] = "XXX";dot[0][1] = "..X";dot[0][2] = "XXX";dot[0][3] = "XXX";dot[0][4] = "X.X";dot[0][5] = "XXX";dot[0][6] = "XXX";dot[0][7] = "XXX";dot[0][8] = "XXX";dot[0][9] = "XXX";
    // line_2
    dot[1][0] = "X.X";dot[1][1] = "..X";dot[1][2] = "..X";dot[1][3] = "..X";dot[1][4] = "X.X";dot[1][5] = "x..";dot[1][6] = "X..";dot[1][7] = "..X";dot[1][8] = "X.X";dot[1][9] = "X.X";
    //line_3
    dot[2][0] = "X.X";dot[2][1] = "..X";dot[2][2] = "XXX";dot[2][3] = "XXX";dot[2][4] = "XXX";dot[2][5] = "XXX";dot[2][6] = "XXX";dot[2][7] = "..X";dot[2][8] = "XXX";dot[2][9] = "XXX";
    //line_4
    dot[3][0] = "X.X";dot[3][1] = "..X";dot[3][2] = "X..";dot[3][3] = "..X";dot[3][4] = "..X";dot[3][5] = "..X";dot[3][6] = "X.X";dot[3][7] = "..X";dot[3][8] = "X.X";dot[3][9] = "..X";
    //line_5
    dot[4][0] = "XXX";dot[4][1] = "..X";dot[4][2] = "XXX";dot[4][3] = "XXX";dot[4][4] = "..X";dot[4][5] = "XXX";dot[4][6] = "XXX";dot[4][7] = "..X";dot[4][8] = "XXX";dot[4][9] = "XXX";
    int n, num[N];
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%1d", &num[i]);   // 每次读取一个数字
    for(int i = 0; i <= 4; i++){
        if(n == 1){       
            printf("%s\n", dot[i][num[n-1]]);
        }else{
            for(int j = 0; j < n-1; j++) 
                printf("%s.", dot[i][num[j]]);
            printf("%s\n", dot[i][num[n-1]]);
        }  
    }
    return 0;
}

参考答案一

这里是引用作者GoldenLegendary的答案

#include<stdio.h>
int main(void)
{
	int n, i;
	char a[10][4] = { {"XXX"}, { "..X"},{"XXX"}, {"XXX"},{"X.X"},{"XXX"},{"XXX"},{"XXX"},{"XXX"},{"XXX"}};
	char b[10][4] = { {"X.X"}, { "..X"},{"..X"}, {"..X"},{"X.X"},{"X.."},{"X.."},{"..X"},{"X.X"},{"X.X"}};
	char c[10][4] = { {"X.X"}, { "..X"},{"XXX"}, {"XXX"},{"XXX"},{"XXX"},{"XXX"},{"..X"},{"XXX"},{"XXX"}};
	char d[10][4] = { {"X.X"}, { "..X"},{"X.."}, {"..X"},{"..X"},{"..X"},{"X.X"},{"..X"},{"X.X"},{"..X"}};
	char e[10][4] = { {"XXX"}, { "..X"},{"XXX"}, {"XXX"},{"..X"},{"XXX"},{"XXX"},{"..X"},{"XXX"},{"XXX"}};
	scanf("%d", &n);
	char temp[100];
	scanf("%s", temp);
	for (i = 0; i < n; i++)
	{
		printf("%s", a[temp[i] - 48]);
		if (i != n - 1)
		{
			printf(".");
		}
	}
	printf("\n");
	for (i = 0; i < n; i++)
	{
		printf("%s", b[temp[i] - 48]);
		if (i != n - 1)
		{
			printf(".");
		}
	}
	printf("\n");
	for (i = 0; i < n; i++)
	{
		printf("%s", c[temp[i] - 48]);
		if (i != n - 1)
		{
			printf(".");
		}
	}
	printf("\n");
	for (i = 0; i < n; i++)
	{
		printf("%s", d[temp[i] - 48]);
		if (i != n - 1)
		{
			printf(".");
		}
	}
	printf("\n"); 
	for (i = 0; i < n; i++)
	{
		printf("%s", e[temp[i] - 48]);
		if (i != n - 1)
		{
			printf(".");
		}
	}
	printf("\n");
	return(0);
}

参考答案二

这里是引用作者 昕星屿 的答案

#include <stdio.h>
//用字符串解的题,所以说和输入的个数没关系了
int main(){
    int n;//无用
    scanf("%d",&n);//无用
    char a[300];
    scanf("%s",&a);//输入字符串
    for(int m=0;m<5;m++) {//输出一共是五行,一行一行的判断输出
        for (int i = 0; i < strlen(a); i++) {//一共有多少个数字
            int j = a[i] - '0';//字符转换为数字
            if (m == 0) {//第一行
                if (j == 0) {
                    printf("XXX");
                } else if (j == 1) {
                    printf("..X");
                } else if (j == 2) {
                    printf("XXX");
                } else if (j == 3) {
                    printf("XXX");
                } else if (j == 4) {
                    printf("X.X");
                } else if (j == 5) {
                    printf("XXX");
                } else if (j == 6) {
                    printf("XXX");
                } else if (j == 7) {
                    printf("XXX");
                } else if (j == 8) {
                    printf("XXX");
                } else if (j == 9) {
                    printf("XXX");
                }
            } else if (m == 1) {//第二行
                if (j == 0) {
                    printf("X.X");
                } else if (j == 1) {
                    printf("..X");
                } else if (j == 2) {
                    printf("..X");
                } else if (j == 3) {
                    printf("..X");
                } else if (j == 4) {
                    printf("X.X");
                } else if (j == 5) {
                    printf("X..");
                } else if (j == 6) {
                    printf("X..");
                } else if (j == 7) {
                    printf("..X");
                } else if (j == 8) {
                    printf("X.X");
                } else if (j == 9) {
                    printf("X.X");
                }
            } else if (m == 2) {//第三行
                if (j == 0) {
                    printf("X.X");
                } else if (j == 1) {
                    printf("..X");
                } else if (j == 2) {
                    printf("XXX");
                } else if (j == 3) {
                    printf("XXX");
                } else if (j == 4) {
                    printf("XXX");
                } else if (j == 5) {
                    printf("XXX");
                } else if (j == 6) {
                    printf("XXX");
                } else if (j == 7) {
                    printf("..X");
                } else if (j == 8) {
                    printf("XXX");
                } else if (j == 9) {
                    printf("XXX");
                }
            } else if (m == 3) {//第四行
                if (j == 0) {
                    printf("X.X");
                } else if (j == 1) {
                    printf("..X");
                } else if (j == 2) {
                    printf("X..");
                } else if (j == 3) {
                    printf("..X");
                } else if (j == 4) {
                    printf("..X");
                } else if (j == 5) {
                    printf("..X");
                } else if (j == 6) {
                    printf("X.X");
                } else if (j == 7) {
                    printf("..X");
                } else if (j == 8) {
                    printf("X.X");
                } else if (j == 9) {
                    printf("..X");
                }
            } else if (m == 4) {//第五行
                if (j == 0) {
                    printf("XXX");
                } else if (j == 1) {
                    printf("..X");
                } else if (j == 2) {
                    printf("XXX");
                } else if (j == 3) {
                    printf("XXX");
                } else if (j == 4) {
                    printf("..X");
                } else if (j == 5) {
                    printf("XXX");
                } else if (j == 6) {
                    printf("XXX");
                } else if (j == 7) {
                    printf("..X");
                } else if (j == 8) {
                    printf("XXX");
                } else if (j == 9) {
                    printf("XXX");
                }
            }
            if (i != (strlen(a)-1)){//如果不是最后一个数字中间就有一个.
                printf(".");
            }

        }
        printf("\n");
    }
    return 0;
}

  • 16
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值