Pagini recente » Cod sursa (job #1904966) | Cod sursa (job #492031) | Clasament dupa rating | Clasament dupa rating | Cod sursa (job #1551243)
#include <fstream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;
ifstream in("cifre.in");
ofstream out("cifre.out");
const int nmax = 1000000;
int a, b, c, k, dif, cnt;
double rasp;
bool Check(int x)
{
int cnt = 0;
do {
cnt += (x%10 == c);
x /= 10;
} while (x);
return cnt>=k;
}
int main() {
int player_unu=0;
in>>a>>b>>c>>k;
dif = b - a + 1;
if(dif<=nmax)
{
for(int i = a; i<=b; i++)
cnt += Check(i);
rasp = double(cnt) / dif;
}
else
{
srand(time(0));
for(int i = 0; i<nmax; i++)
cnt += Check(rand() % dif + a);
rasp = double(cnt) / nmax;
}
out<<setprecision(4)<<fixed<<rasp<< "\n";
return player_unu;
}