显示屏-洛谷,使用char数组,暴力解法

本文介绍了如何使用C++编程语言,通过预先定义的字符数组来表示0-9的数字样式,并实现按行横排输出给定字符串中的数字,适用于计算机科学教育中的示例10,来自洛谷在线平台。
摘要由CSDN通过智能技术生成
#include<iostream>
using namespace std;
int n,a[105];
char s[5][44]={
    "XXX..XXXXXXXX.XXXXXXXXXXXXXXXX",
    "X.X..X..X..XX.XX..X....XX.XX.X",
    "X.X..XXXXXXXXXXXXXXXX..XXXXXXX",
    "X.X..XX....X..X..XX.X..XX.X..X",
    "XXX..XXXXXXX..XXXXXXX..XXXXXXX",
};
int main()
{
    cin>>n;
    string a;
    cin>>a;
    for(int i=0;i<5;i++)
    {
        for(int j=0;j<a.length();j++)
        {
        if(a[j]=='0'){
           for(int t=0;t<=2;t++)
           {
            cout<<s[i][t];
           }
        } 
        else if(a[j]=='1')
        {
            for(int t=3;t<=5;t++)
           {
            cout<<s[i][t];
           }

        }  
        else if(a[j]=='2'){
            for(int t=6;t<=8;t++)
           {
            cout<<s[i][t];
           }
        }
        else if(a[j]=='3'){
            for(int t=9;t<=11;t++)
           {
            cout<<s[i][t];
           }
            
        }
        else if(a[j]=='4'){
            for(int t=12;t<=14;t++)
           {
            cout<<s[i][t];
           }
        }
        else if(a[j]=='5'){
            for(int t=15;t<=17;t++)
           {
            cout<<s[i][t];
           }
        }
        else if(a[j]=='6'){
            for(int t=18;t<=20;t++)
           {
            cout<<s[i][t];
           }
        }
        else if(a[j]=='7'){
            for(int t=21;t<=23;t++)
           {
            cout<<s[i][t];
           }
        }
        else if(a[j]=='8'){
            for(int t=24;t<=26;t++)
           {
            cout<<s[i][t];
           }
        }
        else if(a[j]=='9'){
            for(int t=27;t<=29;t++)
           {
            cout<<s[i][t];
           }
        }
        if(j!=n-1){
		
        cout<<".";
       }
        }
        cout<<endl;

    }
    
}

P5730 【深基5.例10】显示屏 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

提前将0-9个数字的样式用char数组存储,之后横排输出,遍历到的每个数字

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值