Задание: Дан текстовый файл с изображениями целых чисел. В
выходной файл
поместить обратные величины двухзначных чисел. Пример: для 26 – 0.038,
для 87 – 0.011, и т.д. На экран вывести количество чисел во входном
файле, количество чисел в выходном файле, размер входного и выходного
файла в байтах.
Исходный код:
uses crt; function ProvNaDvuznach(x:integer):boolean; var
k:byte; ost:integer; begin k:=0;
ProvNaDvuznach:=false; repeat ost:=x mod
10; k:=k+1; x:=x div 10;
until x=0; if k=2 then ProvNaDvuznach:=true;
end; function Obratnoe(x:integer):real; begin
Obratnoe:=1/x; end; var Fin,Fout:text;
slovo,st,st1:string; razvh,razvih:integer;
chislo,code,col:integer; vh,vih,ks,ks2,i,a:integer;
F:boolean; sum,sum2:longint;
BEGIN ClrScr;
assign(Fin,'f:\vh.txt'); {$I-} reset(Fin); {$I+} sum:=0;
ks:=0; sum2:=0; ks2:=0; col:=0; F:=false; if IOResult<>0
then begin TextColor(4);
writeln(' File Error'); readln;
Halt; end; textcolor(14); writeln('Vhodnoi
fail:'); while not EOF (Fin) do begin
readln(Fin,st); Val(st,chislo,code); if
ProvNaDvuznach(chislo)=true then begin
textcolor(4); write(st,'
'); end
else begin
textcolor(15); write(st,'
'); end;
ks:=ks+1; inc(sum, Length(st)); if st=' ' then
inc(sum); if st<>' ' then vh:=vh+1; if
ProvNaDvuznach(chislo)=true then F:=true; end;
razvh:=2*ks+sum; writeln; TextColor(15); if F=false
then writeln('V faile dvuhznachnyh chisel net!!!')
else begin Reset(Fin);
assign(Fout,'f:\vih.txt'); rewrite(Fout);
textcolor(14); writeln; writeln('Dvuznachnie
chisla, zapisannie vo vhodnoi fail:'); while not eof(Fin)
do begin readln(Fin,st);
Val(st,chislo,code); if ProvNaDvuznach(chislo)=true
then begin
textcolor(14); write('Chislo: ');
textcolor(2); write(chislo);
textcolor(14); write(', obratne emu:');
textcolor(4);
writeln(obratnoe(chislo):6:3,' ');
writeln(Fout,st,' -',obratnoe(chislo):6:3); end;
end; end; reset(Fout); while not EOF
(Fout) do begin readln(Fout,st1);
val (st,chislo,code); ks2:=ks2+1;
inc(sum2,Length(st1)); if st1<>' ' then vih:=vih+1;
end; vih:=vih*2; razvih:=sum2+ks2*2;
Textcolor(14); writeln; write('Kolichestvo chisel v
vhodnom faile:'); Textcolor(4); writeln(vh);
Textcolor(14); write('Kolichestvo chisel vo vihodnom faile:');
Textcolor(4); writeln(vih); writeln;
Textcolor(14); write('Razmer vhodnogo faila: ');
Textcolor(4); writeln(razvh,' bait(ov)'); Textcolor(14);
write('Razmer vihodnogo faila: '); Textcolor(4);
writeln(razvih,' bait(ov)'); close(Fin); close(Fout);
{end; } readkey; end.
|