题意:给出两个显示不全的时间,第一个时间是精确的时间,第二个时间慢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;
}