C - Time

本文介绍了一种使用字符数组来实现数字钟显示的方法。通过输入四个整数,程序能够输出对应的时间显示图形。文章还讨论了字符数组的赋值方法,并提供了一个简单的示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Digital clock use 4 digits to express time, each digit is described by 3*3 characters (including”|”,”_”and” “).now given the current time, please tell us how can it be expressed by the digital clock.

Input

There are several test cases. 
Each case contains 4 integers in a line, separated by space. 
Proceed to the end of file.

Output

For each test case, output the time expressed by the digital clock such as Sample Output.

Sample Input

1 2 5 6
2 3 4 2

Sample Output

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

Hint

The digits showed by the digital clock are as follows:
   _  _     _  _  _  _  _  _ 
 | _| _||_||_ |_   ||_||_|| |
 ||_  _|  | _||_|  ||_| _||_|

就是输入四个数字,输出对应的图形。 

但是我忘记了怎么给字符数组赋值(哭),比赛完又看了看,发现以前学的东西真的记不住啊!还是要认真做笔记!

赋值:

char name[4][8] = {{"Canada "},{"Canada "},{"Canada "},{"Canada "} };

或者

char c[5][50]= {

" _ _ _ _ _ _ _ _ ",

"| | | _| _||_||_ |_ ||_||_|",

"|_| ||_ _| | _||_| ||_| _|",

};

这样一行一行赋值,外围需要大括号,内部每组用引号括起来,逗号隔开。

不可以先定义后后赋值

除非借助strcpy(a,“safa”);

其他的没什么说的,注意格式就行了。

#include<stdio.h>
#include<string.h>
char c[5][50]=
{
    " _     _  _     _  _  _  _  _ ",
    "| |  | _| _||_||_ |_   ||_||_|",
    "|_|  ||_  _|  | _||_|  ||_| _|",
};
int main()
{
    int k[5];
   while(~scanf("%d %d %d %d",&k[0],&k[1],&k[2],&k[3]))
    for(int h=0; h<3; h++)
    {
        for(int i=0; i<4; i++)
        {
            for(int j=k[i]*3; j<k[i]*3+3; j++)
            {
                printf("%c",c[h][j]);
            }
        }
        printf("\n");
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值