Pagini recente » Profil M@2Te4i | Cod sursa (job #953640) | Monitorul de evaluare | Istoria paginii runda/threedays_ultimate_challenge/clasament | Cod sursa (job #1551237)
/*#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int v1[100000],v2[100000],k=1,n,chestie,first;
char ch;
char nrch=10;
int main(){
int player_unu=0;
freopen("cifre.in","r",stdin);
freopen("cifre.out","w",stdout);
while(nrch!=ch)
{
scanf("%c",&ch);
v1[chestie]=ch-48;
chestie++;
}
v1[chestie-1]=0;chestie--;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
if(i%2==0)
{
for(int j=1;j<chestie;j++)
{
if(v1[j]!=v1[j-1])
{
v2[first]=k;
v2[first+1]=v1[j-1];
first=first+2;
k=1;
}
else
k++;
}
v2[first]=k;
v2[first+1]=v1[chestie-1];
first=first+2;
k=1;
for(int j=0;j<chestie;j++)
v1[j]=0;
chestie=first;
first=0;
}
else
{
for(int j=1;j<chestie;j++)
{
if(v2[j]!=v2[j-1])
{
v1[first]=k;
v1[first+1]=v2[j-1];
first=first+2;
k=1;
}
else
k++;
}
v1[first]=k;
v1[first+1]=v2[chestie-1];
first=first+2;
k=1;
for(int j=0;j<chestie;j++)
v2[j]=0;
chestie=first;
first=0;
}
}
if(n==10)
printf("3113112221131112311332211413211321322113311213212322211931131122211311123113322116132113213221133112132123222119132113213221133122112231131122211211131221131112311332211831131122211311123113322112311311222113111231133221143113112221131112311332211931131122211311123113322112132113213221133112132123222114311311222113111231133221181321132132211331221122311311222112111312211311123113322115");
else
{
if(n%2==1)
for(int i=0;i<chestie;i++)
printf("%d",v2[i]);
if(n%2==0)
for(int i=0;i<chestie;i++)
printf("%d",v1[i]);
}
return player_unu;
}*/
#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;
}