#include #include using namespace std; void vypis(string a); string ziskej(short cislo, short radek); void nacti(string a); void parsuj(); string a; string buffer[7]; string poznej(string cif[7]); int main() { getline(cin,a); while(a!="end") { nacti(a); getline(cin,a); } cout << "end" << endl; return 0; } string ziskej(short cislo, short radek) { string nula[7] = {"+---+","| |","| |","+ +","| |","| |","+---+"}; string jedna[7] = {" +"," |"," |"," +"," |"," |"," +"}; string dva[7] = {"+---+"," |"," |","+---+","| ","| ","+---+"}; string tri[7] = {"+---+"," |"," |","+---+"," |"," |","+---+"}; string ctyri[7] = {"+ +","| |","| |","+---+"," |"," |"," +"}; string pet[7] = {"+---+","| ","| ","+---+"," |"," |","+---+"}; string sest[7] = {"+---+","| ","| ","+---+","| |","| |","+---+"}; string sedm[7] = {"+---+"," |"," |"," +"," |"," |"," +"}; string osm[7] = {"+---+","| |","| |","+---+","| |","| |","+---+"}; string devet[7] = {"+---+","| |","| |","+---+"," |"," |","+---+"}; switch( cislo ) { case 0: return nula[radek]; break; case 1: return jedna[radek]; break; case 2: return dva[radek]; break; case 3: return tri[radek]; break; case 4: return ctyri[radek]; break; case 5: return pet[radek]; break; case 6: return sest[radek]; break; case 7: return sedm[radek]; break; case 8: return osm[radek]; break; case 9: return devet[radek]; break; } return ""; } void nacti(string a) { buffer[0]=a; for(int i = 1; i<7; i++){ getline(cin,a); buffer[i]=a; } getline(cin,a); getline(cin,a); parsuj(); } string poznej(string cif[7]) { string res = ""; // prochazeni vsech cifernula[radek]; for(int i = 0; i <10 ; i++){ //prochazeni radku for(int j=0;j < 7; j++) { string temp = ziskej(i,j); //prochazeni znaku for(int k=0;k< 5;k++) { if(cif[j][k] == '.') continue; if(cif[j][k] != temp[k]) goto navesti; } } res += (i+48); navesti: continue; } return res; } unsigned int chtoi(char cislo) { switch( cislo ) { case '0': return 0; break; case '1': return 1; break; case '2': return 2; break; case '3': return 3; break; case '4': return 4; break; case '5': return 5; break; case '6': return 6; break; case '7': return 7; break; case '8': return 8; break; case '9': return 9; break; } return 10; } void parsuj() { string cif[4][7]; string res[4]; int hodiny,minuty; string hod, min; short poceth = 0,pocetm = 0; for(int i = 0; i <7 ; i++) { cif[0][i]=buffer[i].substr(0,5); cif[1][i]=buffer[i].substr(7,5); cif[2][i]=buffer[i].substr(17,5); cif[3][i]=buffer[i].substr(24,5); } for(int i = 0; i < 4; i++) { res[i]=poznej(cif[i]); } for(unsigned int i = 0; i 20) continue; for(unsigned int j = 0; j < res[1].length();j++){ hodiny+=chtoi(res[1][j]); if(hodiny<24) { poceth++; hod=res[0][i]; hod+=res[1][j]; } } } for(unsigned int i = 0; i < 4; i++) { res[i]=poznej(cif[i]); } for(unsigned int i = 0; i 50) continue; for(unsigned int j = 0; j < res[1].length();j++){ minuty+=chtoi(res[3][j]); if(minuty<60) { pocetm++; min=res[2][i]; min+=res[3][j]; } } } if(poceth==1 && pocetm==1) cout<< hod << ":" << min << endl; else cout<<"ambiguous"<< endl; }