Cod sursa(job #550153)

Utilizator toniobFMI - Barbalau Antonio toniob Data 9 martie 2011 11:55:25
Problema Cifre Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 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;
}

void citire () {
	freopen ("cifre.in", "r", stdin);
	freopen ("cifre.out", "w", stdout);
	
	scanf ("%d%d%d%d", &a, &b, &c, &k);
}

void exe () {
	srand(time(0));
	pos = cate = 1003000;
	int x;
	while (cate--) {
		x = a + rand () % (b - a + 1);
		if (verificare (x)) {
			++rez;
		}
	}
}

void afisare () {
	printf ("%.4lf", (double) rez / (double) pos);
}

int main () {
	citire ();
	
	exe ();
	
	afisare ();
	
	return 0;
}