#include #include #include char input[7][32]; char cisla[10][7][6] = { { "+---+", "| |", "| |", "+ +", "| |", "| |", "+---+"}, { " +", " |", " |", " +", " |", " |", " +"}, { "+---+", " |", " |", "+---+", "| ", "| ", "+---+"}, { "+---+", " |", " |", "+---+", " |", " |", "+---+"}, { "+ +", "| |", "| |", "+---+", " |", " |", " +"}, { "+---+", "| ", "| ", "+---+", " |", " |", "+---+"}, { "+---+", "| ", "| ", "+---+", "| |", "| |", "+---+"}, { "+---+", " |", " |", " +", " |", " |", " +"}, { "+---+", "| |", "| |", "+---+", "| |", "| |", "+---+"}, { "+---+", "| |", "| |", "+---+", " |", " |", "+---+"}}; bool checknum(int num, int pos) { for (int i = 0; i < 7; i++) for (int j = 0; j < 5; j++) { //printf("checknum %d, %d: input je '%c' a cisla '%c'\n", num, pos, input[i][j+pos], cisla[num][i][j]); if (input[i][j+pos] != '.' && input[i][j+pos] != cisla[num][i][j]) return false; } //printf("checknum %d %d\n", num, pos); return true; } int candidate(int pos, int max = 10) { int c = -2; for (int cand = 0; cand < max; cand++) { if (checknum(cand, pos)) { if (c >= 0) return -1; c = cand; } } return c; } void analyze() { int a, b, c, d; d = candidate(24); if (d == -1) { printf("ambiguous\n"); return; } c = candidate(17, 6); if (c == -1) { printf("ambiguous\n"); return; } int abr = -2; for (int ab = 0; ab < 24; ab++) { if (checknum(ab / 10, 0) && checknum(ab % 10, 7)) { if (abr >= 0) { abr = -1; break; } abr = ab; } } if (abr == -1) { printf("ambiguous\n"); return; } a = abr / 10; b = abr % 10; printf("%d%d:%d%d\n", a, b, c, d); } bool readinput() { char s[32]; gets(s); if (strncmp(s, "end", 3) == 0) return false; for (int i = 0; i < 7; i++) { strcpy(input[i], s); //printf("vstup %d: %s\n", i, input[i]); gets(s); } gets(s); return true; } int main() { while(readinput()) analyze(); printf("end\n"); return 0; }