Cod sursa(job #161743)

Utilizator netedu_andreiFII Andrei Netedu netedu_andrei Data 18 martie 2008 19:12:07
Problema Cifre Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.72 kb
var f,g:text;
    a,b,k,c,j,i,l,aux,s,p:longint;
    pr:real;
begin
assign(f,'cifre.in');reset(f);
assign(g,'cifre.out');rewrite(g);
readln(f,a,b,c,k);
s:=0;
p:=b-a+1;
l:=0;
aux:=a;
while aux>0 do
      begin
      l:=l+1;
      aux:=aux div 10;
      end;
if l<k then begin
            while l<k do
                  begin
                  a:=a*10;
                  l:=l+1;
                  end;
            end;
for i:=a to b do
    begin
    aux:=i;
    l:=0;
    while aux>0 do
          begin
          if aux mod 10=c then l:=l+1;
          aux:=aux div 10;
          if l=k then break;
          end;
    if l=k then s:=s+1;
    end;
pr:=s/p;
writeln(g,pr:5:4);
close(f);
close(g);
end.