#include #include char string[36]; int b_a,b_z; int pole[36]; int baseOK(int start,int stop){ int i; if (start==stop){ i=(string[start]>='2'); }else{ i=(string[start]!='0'); } return i; } int mensi(int x_a,int x_z,int y_a,int y_z){ int i; if (!(i=(string[x_a]0)) i=mensi(x_a+1,x_z,y_a+1,y_z); } /*printf("i %d, xa %d, xz %d, y_a %d, y_z %d\n",i,x_a,x_z,y_a,y_z);*/ return i; } int cisloOK(start,stop){ int i; if ((i=((stop-start)>=0))){ /* alespon jeden znak */ i=((string[start]!=0)||((stop-start)==0)); /* bud jedina cifra, nebo nesmi byt vedouci 0*/ if (i){ /* jeste musi byt mensi nez base */ if ((stop-start)==(b_z-b_a)){ /* cislo je stejne dlouhe jako base a musi se dal porovnavat*/ i=mensi(start,stop,b_a,b_z); } } } return i; } void pocet_cisel(start,stop){ int n=0; int i=0; for (i=stop;((i>=0)&&((stop-i)<=(b_z-b_a)));i--){ /*cyklus postupne pribira znaky od konce k zacatku, max tolik kolik je v bazi*/ if (cisloOK(i,stop)){ pole[i]+=pole[stop+1]; } } if (stop>start){ pocet_cisel(start,stop-1); } /* return pole[0];*/ } int main(void){ int n; int j; gets(string); while (string[0]!='#'){ b_z=strlen(string)-1; n=0; if ((b_z>0)&&(string[0]!='0')){ /* cislo muze mit smysl -dost dlouhe, nezacina 0 */ for (b_a=b_z;b_a>=1;b_a--){ /* v cyklu zkousim baze*/ if (baseOK(b_a,b_z)) { for (j=0;j<36;j++) pole[j]=0; /*nulovani dyn. pole */ pole[b_a]=1; pocet_cisel(0,b_a-1); /*n=n+pocet_cisel(0,b_a-1);*/ n=n+pole[0]; } /* printf("--- n %d %s\n",n,&string[b_a]);*/ } } if (n>0){ printf("The code %s can represent %d numbers.\n",string,n); }else{ printf("The code %s is invalid.\n",string); } gets(string); } return(0); }