Cod sursa(job #982994)

Utilizator DaNutZ2UuUUBB Bora Dan DaNutZ2UuU Data 10 august 2013 16:50:18
Problema Cifre Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.18 kb
#include <fstream>
#include <vector>
#include <iomanip>
 
using namespace std;
 
ifstream f("cifre.in");
ofstream g("cifre.out");
 
const int MAX=1000000;
const int pM=10000;
const int fc[6]={1000,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;
}