An accutron shows time with four digits, from 0000 to 2359. Every digit is represented by 3*3 characters, including '|'s, '_'s and blanks. When the LCD screen works well, the digits look like the following:
_ _ _ _ _ _ _ _ | | | _| _||_||_ |_ ||_||_| |_| ||_ _| | _||_| ||_| _|
There are two accutrons at hand. One shows the accurate time, and the other is 15 minutes late. For example, at 8:25am, the first accutron shows '0825', while the second shows '0810'.
Unfortunately, there is something wrong with the two LCD screens, namely some parts of the digits missed. Your task is to decide the accurate time, according to the fragmental digits showed on the two accutrons.
Input
The first line of the input is a single integer t (1 <= t <= 20), the number of test cases. Each case contains three lines, indicating the time on the accurate accutron and the time on the slow accutron, separated by a blank column. (Please refer to the Sample Input.)
Output
For each input, print the accurate time with four digits if it can be ensured, or otherwise the string 'Not Sure'.
Sample Input
2 _ _ _ _ _ | _ _|| _ || | _ |_ | | _ |_| _ _ _ _ _ _ ||_ _|| _| || | _ |_ | || |_|
Sample Output
Not Sure 0825
// 暴力模拟
#include<stdio.h>
#include<string.h>
#include<iostream>
//const int ddd = 1;
const int ddd = 0;
int d1[10];
int d2[10];
char a[10][50];
int ans;
int ansh,ansm;
const char s[][50] = {
" _ _ _ _ _ _ _ _ ",
"| | | _| _||_||_ |_ ||_||_|",
"|_| ||_ _| | _||_| ||_| _|"
};
void init(){
memset(d1,0,sizeof(d1));
memset(d2,0,sizeof(d2));
memset(a,0,sizeof(a));
ans = 0;
}
void showd(){
printf("D1: ");
for(int i = 0;i<4;i++){
printf("%d",d1[i]);
}
printf("\nD2: ");
for(int i = 0;i<4;i++){
printf("%d",d2[i]);
}
printf("\n");
}
void gend(int h1,int m1,int h2,int m2){
// if(ddd){
// printf("gend : %d %d -> %d %d\n",h1,m1,h2,m2);
// }
d1[0] = h1/10;
d1[1] = h1%10;
d2[0] = h2/10;
d2[1] = h2%10;
d1[2] = m1/10;
d1[3] = m1%10;
d2[2] = m2/10;
d2[3] = m2%10;
// if(ddd)showd();
}
bool cmpd(int b,int ii){
// a b b+3
// s d1[0] d1[1]
for(int i = 0;i<4;i++){
int d = ii==1?d1[i]:d2[i];
if(ddd)printf("d%d = %d\n",ii,d);
for(int j = 0;j<3;j++){
int ida = b+i*3+j;
int idd = d*3+j;
for(int k = 0;k<3;k++){
if(a[k][ida] == s[k][idd])continue;
if(a[k][ida] != ' '&&s[k][idd]!=a[k][ida])return false;
}
}
}
return true;
}
void shows(){
for(int i = 0;i<3;i++){
for(int j = 0;j<26;j++){
printf("%c",a[i][j]);
}
printf("\n");
}
}
int main(){
int nn;
scanf("%d",&nn);
getchar();
while(nn--){
init();
for(int i = 0;i<3;i++){
gets(a[i]);
}
if(ddd)shows();
//
int h = 0,m = 0;
for(int h = 0;h<24;h++){
for(int m = 0;m<60;m++){
// 计算推迟15分钟的时间
int h2 = h;
int m2 = m-15;
if(m2<0){
h2--;
m2 += 60;
}
if(h2<0){
h2+= 24;
}
gend(h,m,h2,m2);
// if(ddd)showd();
// d1 0825 d2 0810
// c1 c2
bool r1 = cmpd(0,1)&&cmpd(13,2);
// bool r2 = cmpd(13,1)&&cmpd(0,2);
bool r2 = false;
if(r1||r2){
ans++;
ansh = h;
ansm = m;
if(ans == 2){
if(ddd)showd();
break;
}
}
if(ans == 2)break;
}
if(ans == 2)break;
}
if(ans ==1){
printf("%02d%02d\n",ansh,ansm);
}
else{
printf("Not Sure\n");
}
}
}