Pagini recente » Borderou de evaluare (job #1578051) | Borderou de evaluare (job #5200) | Cod sursa (job #1251404) | Cod sursa (job #402501) | Cod sursa (job #300194)
Cod sursa(job #300194)
#include <stdio.h>
#define NR 10
FILE *f=fopen("cifre.in", "r"), *g=fopen("cifre.out", "w");
long n, j, i, a, b, c, k, sw, total, t, x[10][10], nrb, nra, s, left, right;
void preprocesare(void)
{
x[1][0]=8;
x[1][1]=1;
x[1][2]=0;
x[1][3]=0;
x[1][4]=0;
x[1][5]=0;
x[1][6]=0;
x[1][7]=0;
x[1][8]=0;
x[1][9]=0;
x[2][0]=80;
x[2][1]=18;
x[2][2]=1;
x[2][3]=0;
x[2][4]=0;
x[2][5]=0;
x[2][6]=0;
x[2][7]=0;
x[2][8]=0;
x[2][9]=0;
x[3][0]=728;
x[3][1]=243;
x[3][2]=27;
x[3][3]=1;
x[3][4]=0;
x[3][5]=0;
x[3][6]=0;
x[3][7]=0;
x[3][8]=0;
x[3][9]=0;
x[4][0]=6560;
x[4][1]=2916;
x[4][2]=486;
x[4][3]=36;
x[4][4]=1;
x[4][5]=0;
x[4][6]=0;
x[4][7]=0;
x[4][8]=0;
x[4][9]=0;
x[5][0]=59048;
x[5][1]=32805;
x[5][2]=7290;
x[5][3]=810;
x[5][4]=45;
x[5][5]=1;
x[5][6]=0;
x[5][7]=0;
x[5][8]=0;
x[5][9]=0;
x[6][0]=531440;
x[6][1]=354294;
x[6][2]=98415;
x[6][3]=14580;
x[6][4]=1215;
x[6][5]=54;
x[6][6]=1;
x[6][7]=0;
x[6][8]=0;
x[6][9]=0;
x[7][0]=4782968;
x[7][1]=3720087;
x[7][2]=1240029;
x[7][3]=229635;
x[7][4]=25515;
x[7][5]=1701;
x[7][6]=63;
x[7][7]=1;
x[7][8]=0;
x[7][9]=0;
x[8][0]=43046720;
x[8][1]=38263752;
x[8][2]=14880348;
x[8][3]=3306744;
x[8][4]=459270;
x[8][5]=40824;
x[8][6]=2268;
x[8][7]=72;
x[8][8]=1;
x[8][9]=0;
x[9][0]=387420488;
x[9][1]=387420489;
x[9][2]=172186884;
x[9][3]=44641044;
x[9][4]=7440174;
x[9][5]=826686;
x[9][6]=61236;
x[9][7]=2916;
x[9][8]=81;
x[9][9]=1;
}
void citeste(void)
{
fscanf(f, "%ld%ld%ld%ld", &a, &b, &c, &k);
total=b-a+1;
}
void rezolva(void)
{
t=b;
nrb=0;
while (t)
{
nrb++;
t*=0.1;
}
t=a;
nra=0;
while (t)
{
nra++;
t*=0.1;
}
if (c>0)
{
for (i=k;i<=9;i++)
s=s+x[nrb][i]-x[nra-1][i];
left=1;
for (i=1;i<=nra;i++)
left*=10;
for (i=left;i<a;i++)
{
sw=0;
t=i;
while (t)
{
if (t%10==c)
sw++;
t*=0.1;
}
if (sw==k)
s--;
}
right=10*left;
for (i=b+1;i<right;i++)
{
sw=0;
t=i;
while (t)
{
if (t%10==c)
sw++;
t*=0.1;
}
if (sw==k)
s--;
}
}
}
void tipareste(void)
{
fprintf(g, "%.4f", (float)s/total);
fcloseall();
}
int main(void)
{
citeste();
preprocesare();
rezolva();
tipareste();
return 0;
}