Cod sursa(job #2046935)

Utilizator Aquaryus0Alexandru Benchea Aquaryus0 Data 24 octombrie 2017 12:03:59
Problema Cifre Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <iostream>
#include <cstdio>

using namespace std;

const int NMAX = 2501;

int a,b,c,k;
void read()
{
    scanf("%d %d %d %d", &a,&b,&c,&k);
}

int nr_cifre(int x)
{
    int nr = 0;
    for(x; x>0; x /= 10)
    {
        if(x%10==c)
            nr++;
        if(k==nr)
            return 1;
    }

    return 0;
}

int main()
{
    freopen("cifre.in", "r", stdin);
    freopen("cifre.out", "w", stdout);
    read();

    double p1 = 0;
    double p2 = b-a+1;

    for(int i=a; i<=b; i++)
        p1 += nr_cifre(i);

    printf("%.4g", p1/p2);
}