2017多校四 1011题 hdu 6077 Time To Get Up 感谢数电老师(。

本文介绍了一种通过分析七段数码管显示状态来识别时间的方法。利用C++编程语言,作者详细解释了如何根据各段是否点亮来确定显示的具体数字,并最终组合成24小时制的时间。

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

题目链接


题意:

Little Q's clock uses a standard 7-segment LCD display for all digits, plus two small segments for the '':'', and shows all times in a 24-hour format. The '':'' segments are on at all times.



Your job is to help Little Q read the time shown on his clock.


思路:

水题无误,但怎么写最好写呢?

陷入沉思.........

叮!

这可是七段数码显示管啊,想想数电课上讲的七段数码显示管的编号,还有当时画的那么多卡诺图(雾

先给七段编号,从右上的那一个顺时针转一圈,六段分别为 1,2,3,4,5,6, 中间一横编为7,判断每段存不存在记在 f 里

这样比如说数字 5 就是 f[2] && f[3] && f[5] && f[6] && f[7] && !f[1] && !f[4],

就很好写了。

(想到这个方法觉得自己真是太机智了然后这一场就没啥别的会做的题了)


AC代码如下:

#include <bits/stdc++.h>
char s[10][50];
bool f[10];
int judge(int l, int r) {
    memset(f, 0, sizeof(f));
    if (s[0][l + 1] == 'X') f[1] = true;
    if (s[1][r] == 'X') f[2] = true;
    if (s[4][r] == 'X') f[3] = true;
    if (s[6][l + 1] == 'X') f[4] = true;
    if (s[4][l] == 'X') f[5] = true;
    if (s[1][l] == 'X') f[6] = true;
    if (s[3][l + 1] == 'X') f[7] = true;
//    printf("%d%d%d%d%d%d%d\n", f[1], f[2], f[3], f[4], f[5], f[6],f[7]);
    if (f[1] && f[2] && f[3] && f[4] && f[5] && f[6] && !f[7]) return 0;
    if (f[2] && f[3] && !f[1] && !f[4] && !f[5] && !f[6] && !f[7]) return 1;
    if (f[1] && f[2] && f[7] &&f[4]&&f[5] && !f[3] && !f[6]) return 2;
    if (f[1] &&f[2]&&f[3]&&f[7] &&f[4]&&!f[5] &&!f[6]) return 3;
    if (f[2]&&f[3]&&f[6]&&f[7]&&!f[1]&&!f[4]&&!f[5]) return 4;
    if (f[1]&&f[3]&&f[6]&&f[7]&&f[4]&&!f[2]&&!f[5]) return 5;
    if (f[1]&&f[3]&&f[4]&&f[5]&&f[6]&&f[7]&&!f[2]) return 6;
    if (f[1]&&f[2]&&f[3]&&!f[4]&&!f[5]&&!f[6]&&!f[7]) return 7;
    if (f[1]&&f[2]&&f[3]&&f[4]&&f[5]&&f[6]&&f[7]) return 8;
    if (f[1]&&f[2]&&f[3]&&f[4]&&!f[5]&&f[6]&&f[7]) return 9;
}
void print(int x) {
    if (x) printf("%d",x);
    else printf("0");
}
void work() {
    for (int i = 0; i < 7; ++i) scanf("%s", s[i]);
    int x1 = judge(0, 3), x2 = judge(5, 8), x3 = judge(12, 15), x4 = judge(17, 20);
    print(x1);
    print(x2);
    printf(":");
    print(x3);print(x4);
    printf("\n");
}
int main() {
//    freopen("in.txt", "r", stdin);
    int T;
    scanf("%d\n", &T);
    while (T--) work();
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值