#include #include #include char pole[10][7][6] = {{ {'+', '-', '-', '-', '+', '\0'}, {'|', ' ', ' ', ' ', '|', '\0'}, {'|', ' ', ' ', ' ', '|', '\0'}, {'+', ' ', ' ', ' ', '+', '\0'}, {'|', ' ', ' ', ' ', '|', '\0'}, {'|', ' ', ' ', ' ', '|', '\0'}, {'+', '-', '-', '-', '+', '\0'} }, { {' ', ' ', ' ', ' ', '+', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {' ', ' ', ' ', ' ', '+', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {' ', ' ', ' ', ' ', '+', '\0'} }, { {'+', '-', '-', '-', '+', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {'+', '-', '-', '-', '+', '\0'}, {'|', ' ', ' ', ' ', ' ', '\0'}, {'|', ' ', ' ', ' ', ' ', '\0'}, {'+', '-', '-', '-', '+', '\0'} } , { {'+', '-', '-', '-', '+', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {'+', '-', '-', '-', '+', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {'+', '-', '-', '-', '+', '\0'}} , { {'+', ' ', ' ', ' ', '+', '\0'}, {'|', ' ', ' ', ' ', '|', '\0'}, {'|', ' ', ' ', ' ', '|', '\0'}, {'+', '-', '-', '-', '+', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {' ', ' ', ' ', ' ', '+', '\0'} }, { {'+', '-', '-', '-', '+', '\0'}, {'|', ' ', ' ', ' ', ' ', '\0'}, {'|', ' ', ' ', ' ', ' ', '\0'}, {'+', '-', '-', '-', '+', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {'+', '-', '-', '-', '+', '\0'} } , { {'+', '-', '-', '-', '+', '\0'}, {'|', ' ', ' ', ' ', ' ', '\0'}, {'|', ' ', ' ', ' ', ' ', '\0'}, {'+', '-', '-', '-', '+', '\0'}, {'|', ' ', ' ', ' ', '|', '\0'}, {'|', ' ', ' ', ' ', '|', '\0'}, {'+', '-', '-', '-', '+', '\0'} }, { {'+', '-', '-', '-', '+', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {' ', ' ', ' ', ' ', '+', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {' ', ' ', ' ', ' ', '+', '\0'}}, { {'+', '-', '-', '-', '+', '\0'}, {'|', ' ', ' ', ' ', '|', '\0'}, {'|', ' ', ' ', ' ', '|', '\0'}, {'+', '-', '-', '-', '+', '\0'}, {'|', ' ', ' ', ' ', '|', '\0'}, {'|', ' ', ' ', ' ', '|', '\0'}, {'+', '-', '-', '-', '+', '\0'}}, { {'+', '-', '-', '-', '+', '\0'}, {'|', ' ', ' ', ' ', '|', '\0'}, {'|', ' ', ' ', ' ', '|', '\0'}, {'+', '-', '-', '-', '+', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {' ', ' ', ' ', ' ', '|', '\0'}, {'+', '-', '-', '-', '+', '\0'}}} ; bool moznost[4][10]; int kok(int x, int zac) { int vysledek = 0; for (int i = zac; i < 10; i++) vysledek += moznost[x][i] == true; return vysledek; } int kolik(int x) { return kok(x, 0); } int min(int x) { for (int i = 0; i < 10; i++) { if (moznost[x][i]) return i; } return -1; } int main(void) { char line[7][30]; char bordel; int offset[4] = {0, 7, 17, 24}; int vysledek[4]; while(1) { int correct = 1; char *a = &(line[0][0]); for (int y = 0; y < 7; y++) { for (int x = 0; x < 29; x++) { scanf("%c", &(line[y][x])); if (line[y][x] == 'e') { printf("end\n"); return 0; } } scanf("%c", &bordel); line[y][29] = '\0'; } scanf("%c", &bordel); scanf("%c", &bordel); for (int poradi = 0; poradi < 4; poradi++) { for (int cislice = 0; cislice < 10; cislice++) { moznost[poradi][cislice] = true; for (int y = 0; y < 7; y++) { for (int x = 0; x < 5; x++) { if (line[y][x+offset[poradi]] == '+' || line[y][x+offset[poradi]] == '-' || line[y][x+offset[poradi]] == ' ') { if (pole[cislice][y][x] != line[y][x + offset[poradi]]) { moznost[poradi][cislice] = false; } } } } } } for (int i = 6; i < 10; i++) moznost[2][i] = false; /* for (int x = 0; x < 4; x++) { for (int i = 0; i < 10; i++) { if (moznost[x][i]) printf("%d ", i); } printf(" = %d\n", kolik(x)); } */ if (kolik(2) != 1 || kolik(3) != 1) { correct = false; } else { vysledek[2] = min(2); vysledek[3] = min(3); } if (correct) { for (int i = 3; i < 10; i++) moznost[0][i] = false; if (!moznost[0][2]) { if (kolik(0) != 1 || kolik(1) != 1) correct = false; else { vysledek[0] = min(0); vysledek[1] = min(1); } } else { if (kolik(0) == 1) { for (int i = 4; i< 10; i++) moznost[1][i] = false; if (kolik(1) != 1) correct = false; else { vysledek[0] = 2; vysledek[1] = min(1); } } else { if (kolik(0) == 3) { correct = 0; } else { int m = min(1); int vetsi = kok(1, 4); if (m < 4) correct = false; else { if (vetsi != 1) correct = false; else { vysledek[0] = min(0); vysledek[1] = m; } } } } } } if (correct) printf("%d%d:%d%d\n", vysledek[0], vysledek[1], vysledek[2], vysledek[3]); else printf("ambiguous\n"); } return 0; }