Cod sursa(job #2344324)

Utilizator SqueekDanielTodasca Daniel SqueekDaniel Data 14 februarie 2019 22:59:56
Problema Cifre Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <bits/stdc++.h>

#define RAND_CONSTANT 100005

int A, B, C, K;
int Match[10][10];

std::ifstream In ("cifre.in");
std::ofstream Out("cifre.out");

void Citire() {
    In >> A >> B >> C >> K;
}

void Rezolvare() {
    srand(time(NULL));

    int found = 0;
    for (int i=0; i<10; ++i)
        Match[i][i] = 1;

    for (int i=0, cnt, V; i<RAND_CONSTANT; ++i) {
        V = rand()%(B-A+1) + A;
        cnt = 0;
        if (V == 0)
            cnt = Match[C][0];
        while (V) {
            cnt += Match[C][V%10];
            V /= 10;
        }

        if (cnt >= K)
            ++found;
    }   Out << std::fixed << std::setprecision(4) << double(found) / RAND_CONSTANT;
}

int main()
{
    Citire();
    Rezolvare();

    return 0;
}