Cod sursa(job #1434368)

Utilizator movo608Moldovan Andrei movo608 Data 10 mai 2015 15:40:39
Problema Cifre Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>

using namespace std;

ifstream f("cifre.in");
ofstream g("cifre.out");

const int MAX=10000;
int A,B,C,K,F,P;

inline int cf(int X)
{   int sol=0 ;
    for(;X;X/=10) if(X%10==C) ++sol;
    return sol ;
}
int main()
{   f>>A>>B>>C>>K;
    if(B-A>=MAX)
    {   for(;A%MAX;++A,++P)
            if(cf(A)>=K) ++F;
        for(int x=0; B-A>=MAX; A+=MAX,P+=MAX)
        {   x=cf(A/MAX);
            if(x>=K) F+=6561;
            if(x>=K-1) F+=2916;
            if(x>=K-2) F+=487;
            if(x>=K-3) F+=35 ;
            if(x>=K-4) ++F ;
        }
    }
    for(;A<=B;++A,++P) if(cf(A)>=K) ++F;
    g<<(double)F/P; g.close(); return 0;
}