Cod sursa(job #1898243)

Utilizator ionut98Bejenariu Ionut Daniel ionut98 Data 1 martie 2017 21:40:38
Problema Cifre Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include<bits/stdc++.h>
#define Random(a,b) (a + (rand() % (b - a + 1)))
using namespace std;
ifstream f("cifre.in");
ofstream g("cifre.out");
const int Lim=1e5;
const int OpMax=5e5;
int a,b,c,k;
inline bool ver(int x)
{
    int con=0;
    while(x)
    {
        con+=(x%10==c);
        x/=10;
    }
    return(con>=k);
}
inline float rez1()
{
    int fav=0;
    for(int i=1;i<=OpMax;i++)
      fav+=ver(Random(a,b));
    return (1.0*fav/OpMax);
}
inline float rez()
{
    int fav=0;
    for(int i=a;i<=b;i++)
      fav+=ver(i);
    return (1.0*fav/(b-a+1));
}
int main()
{
    srand(time(NULL));
    f>>a>>b>>c>>k;
    float ans=0;
    if(b-a<=Lim)
      ans=rez();
    else
      ans=rez1();
    g<<fixed<<setprecision(5)<<ans;
    return 0;
}