Cod sursa(job #500612)

Utilizator cont_de_testeCont Teste cont_de_teste Data 12 noiembrie 2010 16:36:47
Problema Cifre Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cstdlib>
using namespace std;

int a, b, k, c ;

FILE *fin = fopen ("cifre.in", "r");
FILE *fout = fopen ("cifre.out", "w");

int count ( int x, int aux ) {
    char abc[124] ;
    int sol = 0 ;
    sprintf ( abc,"%d",x )  ;
    for ( int i = 0; i <= aux; ++i ) {
        if ( abc[i] - '0' == c ) {
            ++sol ;
        }
    }
    return sol ;
}
int f ( int a ) {
    int aux = log10 ( a ), sol = 0 ;
    for ( int xx = 0; xx < a ; ++xx ) {
		if (count ( xx, aux ) >= k) {
			++sol ;
		}
	}
	return sol ;
}
int main() {
	fscanf (fin, "%d %d %d %d", &a, &b, &c, &k);

	//double ans = (double)count / (double)exps;
	//fprintf (fout, "%.4lf", ans);
	fprintf ( fout, "%.4lf", ( double ) ( f(b + 1) - f(a) ) / ( double ) ( b + 1 - a ) ) ;
	fclose(fout);
	return 0;
}