Cod sursa(job #550256)

Utilizator toniobFMI - Barbalau Antonio toniob Data 9 martie 2011 12:20:32
Problema Cifre Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cstdlib>
using namespace std;

int a, b, c, k, rez, pos, cate;

bool verificare (int x) {
	int cnt = 0;
	while (x) {
		if (x % 10 == c) {
			++cnt;
		}
		x /= 10;
	}
	return cnt >= k;
}

int main () {
	freopen ("cifre.in", "r", stdin);
	freopen ("cifre.out", "w", stdout);
	
	scanf ("%d%d%d%d", &a, &b, &c, &k);
	
	srand(time(0));
	pos = cate = 1005000;
	int x;
	while (cate--) {
		x = a + rand () % (b - a + 1);
			int cnt = 0;
		while (x) {
			if (x % 10 == c) {
				++cnt;
			}
			x /= 10;
		}
		if (cnt >= k) {
			++rez;
		}
	}
	
	printf ("%.4lf", (double) rez / (double) pos);
	
	return 0;
}