poj 1676 What time is it?

8 篇文章 0 订阅

题意:给出两个显示不全的时间,第一个时间是精确的时间,第二个时间慢15分钟,判断是否能推出精确的时间。
分析:直接枚举时间,看能不能匹配到唯一的结果。

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

const char dig[3][50] = {
" _     _  _     _  _  _  _  _ ",
"| |  | _| _||_||_ |_   ||_||_|",
"|_|  ||_  _|  | _||_|  ||_| _|",
};
char s[3][51];

bool match1(int d, int sj)
{
    for(int i = 0; i < 3; i++)
        for(int j = sj, k = d * 3; j < sj + 3; j++, k++)
            if(s[i][j] != ' ' && dig[i][k] == ' ') return false;
    return true;
}

bool Match(int x, int y)
{
    int getd = 1000;
    if(!match1(x / getd, 0)) return false;
    x %= getd;
    getd /= 10;
    if(!match1(x / getd, 3)) return false;
    x %= getd;
    getd /= 10;
    if(!match1(x / getd, 6)) return false;
    x %= getd;
    getd /= 10;
    if(!match1(x / getd, 9)) return false;

    getd = 1000;
    if(!match1(y / getd, 13)) return false;
    y %= getd;
    getd /= 10;
    if(!match1(y / getd, 16)) return false;
    y %= getd;
    getd /= 10;
    if(!match1(y / getd, 19)) return false;
    y %= getd;
    getd /= 10;
    if(!match1(y / getd, 22)) return false;

    return true;
}

int main()
{
    int t;
    scanf("%d", &t);
    getchar();
    while(t--)
    {
        for(int i = 0; i < 3; i++) gets(s[i]);
        int ans, anscnt = 0;
        for(int i = 0; i <= 2359; i++)
        {
            int m = i % 100;
            int h = i / 100;
            if(h >= 24 || m >= 60) continue;
            m -= 15;
            if(m < 0)
            {
                h -= 1;
                m += 60;
                if(h < 0) h += 24;
            }
            if(h >= 24 || m >= 60) continue;
            int j = h * 100 + m;
            if(Match(i, j))
            {
                anscnt++;
                if(anscnt == 2) break;
                ans = i;
            }
        }
        if(anscnt != 1) puts("Not Sure");
        else printf("%04d\n", ans);
    }
    return 0;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值