#include #include int test(char* vzor, char* testovany){ int i; int j; for( i =0; i<35;i++) { if(testovany[i]=='.') continue; if(testovany[i]!=vzor[i]) return -1; } return 1; } int main(){ /*definice konstant*/ int i,j; int res0; int res1; int res2; int res3; int res4; char* nula ="+---+| || |+ +| || |+---+"; char* jednicka =" + | | + | | +"; char* dvojka ="+---+ | |+---+| | +---+"; char* trojka ="+---+ | |+---+ | |+---+"; char* ctyrka ="+ +| || |+---+ | | +"; char* petka ="+---+| | +---+ | |+---+"; char* sestka ="+---+| | +---+| || |+---+"; char* sedmicka ="+---+ | | + | | +"; char* osmicka ="+---+| || |+---+| 1 || |+---+"; char* devitka ="+---+| || |+---+ | |+---+"; char** pole = malloc(40); pole[0]=nula; pole[1]=jednicka; pole[2]=dvojka; pole[3]=trojka; pole[4]=ctyrka; pole[5]=petka; pole[6]=sestka; pole[7]=sedmicka; pole[8]=osmicka; pole[9]=devitka; char* box1 = malloc(35); char* box2 = malloc(35); char* box3 = malloc(35); char* box4 = malloc(35); char* radek= malloc(30); int kombinace=0; int hodin; int minut; do{ for(i=0;i<7;i++){ gets(radek); if( *radek == 'e') {printf("end\n"); return 0;} for(j=0;j<5;j++){ box1[j+i*5]=radek[j]; } for(j=0;j<5;j++){ box2[j+i*5]=radek[j+7]; } for(j=0;j<5;j++){ box3[j+i*5]=radek[j+17]; }res3= test(pole[i],box2); for(j=0;j<5;j++){ box4[j+i*5]=radek[24+j]; } } gets(radek); gets(radek); /*parsing*/ res0= test(nula,box1); res1= test(jednicka,box1); res2= test(dvojka,box1); if((res0 == 1 && res1 == 1)){ printf("ambiguous\n");continue; } for(i=9;i>=0 ;i--) { res3= test(pole[i],box2); if(res3==1) for(j=0;j<9;j++) { res4=test(pole[j],box1); if(res3==1 &&res4==1){ /*zjistena kombinace dvou cisel*/ if((j*10+i)<24) { kombinace++; hodin=j*10+i; } } } } if(kombinace>1) {printf("ambiguous\n");continue;} kombinace=0; for(i=9;i>=0 ;i--) { res3= test(pole[i],box4); if(res3==1) for(j=0;j<9;j++) { res4=test(pole[j],box3); if(res3==1 &&res4==1){ /*zjistena kombinace dvou cisel*/ if((j*10+i)<60) { kombinace++; minut=j*10+i; } } } } if(kombinace>1) {printf("ambiguous\n");continue;} kombinace=0; printf("%2d:%2d\n",hodin,minut); }while(1); return 0; /* ok kod*/ }