Cod sursa(job #2926993)

Utilizator Theodor17Pirnog Theodor Ioan Theodor17 Data 19 octombrie 2022 09:48:53
Problema Cifre Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>
#include <string>

using namespace std;

ifstream cin("cifre.in");
ofstream cout("cifre.out");

int a, b, c, k;

int main(){

    cin >> a >> b >> c >> k;

    int nr = 0;
    for(int i = a; i <= b; i++){

        int temp = i, t = 0;
        while(temp){

            if(temp % 10 == c)
                t++;

            temp /= 10;

        }

        if(t >= k)
            nr++;

    }

    string ans = to_string((double) nr / (b - a + 1));

    int zec = 4;
    bool dot = 0;
    for(int i = 0; zec; i++){

        cout << ans[i];
        zec -= dot;

        if(ans[i] == '.')
            dot = 1;

    }

    return 0;
}