Cod sursa(job #500579)

Utilizator cont_de_testeCont Teste cont_de_teste Data 12 noiembrie 2010 15:44:56
Problema Cifre Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
# include <cstdio>

const char *FIN = "cifre.in", *FOU = "cifre.out" ;

long a,b,c,k,fav,pos,n;
double posib,favor,prob;
long cif(long aa);

int main ( void ) {
    freopen("cifre.in","rt",stdin);
    freopen("cifre.out","wt",stdout);
    scanf("%ld%ld%ld%ld",&a,&b,&c,&k);
    int A = 30 + c, B = 350 + c, C = 2940 + c, D = 10000 - ( 1 + A + B + C ) ;
    if(a+10000<=b) {
        while(a%10000) {
            n=cif(a);
            if(n>=k)fav++;
            a++;
            pos++;
        }
        while(a+10000<=b) {
            n=cif(a/10000);
            if(n+4>=k)fav++;
            if(n+3>=k)fav+=A;
            if(n+2>=k)fav+=B;
            if(n+1>=k)fav+=C;
            if(n>=k)fav+=D;
            a+=10000;
            pos+=10000;
        }
    }
    while(a<=b) {
        n=cif(a);
        if(n>=k)fav++;
        a++;
        pos++;
    }
    posib=(double)pos;
    favor=(double)fav;
    prob=favor/posib;
    printf("%.4lf\n",prob);
    return 0;
}
long cif(long aa) {
    long bb=aa,ret=0;
    while(bb) {
        if(bb%10==c)ret++;
        bb/=10;
    }
    return ret;
}