Cod sursa(job #398393)

Utilizator stef2503Stefan Stan stef2503 Data 18 februarie 2010 17:04:25
Problema Cifre Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <stdio.h>

int cif (int a, int b, int c, int k) 
{
	int i, x, n, s=0;
	for (i=a; i<=b; i++) {
		x=i;
		n=0;
		while (x>0) {
			if (x%10==c) {
				n++;
			}
			x/=10;
			if (n>=k) {
				s++;
				break;
			}
		}
	}
	return s;	
}

int main ()
{
	freopen("cifre.in", "r", stdin);
	freopen("cifre.out", "w", stdout);
	int a, b, c, k, i, x, y, n, s=0;
	scanf("%d %d %d %d", &a, &b, &c, &k);
	if (b-a<10000) {
		s=cif(a, b, c, k);
	} else {
		x=10000;
		y=1000000000;
		while (x<a) {
			x+=10000;
		}
		while(y>b) {
			y-=10000;
		}
		s=cif(a, x, c, k);
		s+=cif(y, b, c, k);
	}
	printf("%d %d\n", x, y);
	float p = (float) s / (float) (b-a+1);
	printf("%.4lf", p);
	return 0;
}