Pagini recente » Cod sursa (job #605591) | Cod sursa (job #3120561) | Cod sursa (job #1091764) | Cod sursa (job #3171268) | Cod sursa (job #983009)
Cod sursa(job #983009)
#include <fstream>
#include <vector>
#include <iomanip>
using namespace std;
ifstream f("cifre.in");
ofstream g("cifre.out");
const int MAX=1000000000;
const int pM=10000;
const int fc[6]={10000,3439,523,36,1,0};
const int o_p=4;
int c_cnt(int x,int c)
{
int sol= 0;
while (x>0)
{
if (x%10==c)
{
++sol;
}
x/= 10;
}
return sol;
}
int main()
{
int a,b,c,k;
f>>a>>b>>c>>k;
int dif=b-a+1;
int sol=0;
if (b-a+1>pM)
{
while (a%pM!=0)
{
if (c_cnt(a, c)>=k)
{
++sol;
}
++a;
}
while (b-a+1>pM)
{
int aux= k-c_cnt(a/pM, c);
if (aux<0)
{
aux= 0;
}
else if (aux>5)
{
aux= 5;
}
sol+= fc[aux];
a+=pM;
}
}
while (a<=b)
{
if (c_cnt(a, c)>=k)
{
++sol;
}
++a;
}
g<<setprecision(o_p)<<fixed;
g<<(double)sol/dif<<'\n';
return 0;
}