Pagini recente » Cod sursa (job #3145063) | Cod sursa (job #1212369)
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
using namespace std;
const int maxRand = 600000;
int A, B, C, K, ans, val;
int CifreC(int N)
{
int cnt = 0;
while(N)
{
if(N % 10 == C) cnt ++;
N /= 10;
}
return (cnt >= K);
}
int main()
{
freopen("cifre.in", "r", stdin);
freopen("cifre.out", "w", stdout);
srand(time(NULL));
int i;
scanf("%i %i %i %i", &A, &B, &C, &K);
if(B - A <= maxRand)
{
ans = 0;
for(i = A; i <= B; i++)
if(CifreC(i))
ans ++;
printf("%.4lf\n", 1.0 * ans / (B - A + 1));
}else
{
ans = 0;
i = maxRand;
while(i)
{
val = (rand() % (B - A + 1)) + A;
if(CifreC(val))
ans ++;
i --;
}
printf("%.4lf\n", 1.0 * ans / maxRand);
}
return 0;
}