Cod sursa(job #729467)

Utilizator robertpoeRobert Poenaru robertpoe Data 29 martie 2012 17:02:35
Problema Cifre Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include<cstdio>
#include<fstream>
using namespace std;
ifstream f("cifre.in");
ofstream g("cifre.out");
int c;
int a,b,k,nr=0,p=0,x;
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>=10000)
    {
        for(;a%10000;++a,++p)
            if (cf(a)>=k)
                ++nr;
        for(x=0;b-a>=10000;a+=10000,p+=10000)
        {
            x=cf(a/10000);
            if (x>=k)
                nr+=6561;
            if (x>=k-1)
                nr+=2916;
            if (x>=k-2)
                nr+=487;
            if (x>=k-3)
                nr+=35;
            if (x>=k-4)
                ++nr;
        }
    }
    for (;a<=b;++a,++p)
        if (cf(a)>=k)
            ++nr;
    g<<(double)nr/p ;
    return 0;
}