Ответ:
program Test;
const
L = ['а'..'я', 'А'..'Я'];
N = ['0'..'9'];
var
f: Text;
s: AnsiString;
cl, cn, i: Integer;
begin
Assign (f, 'text.txt'); // здесь название файла
Reset (f);
cl := 0;
cn := 0;
while not Eof (f) do begin
ReadLn (f, s);
for i := 1 to Length (s) do begin
if s [i] in L then
Inc (cl)
else if s [i] in N then
Inc (cn);
end;
end;
Close (f);
WriteLn ('Русских букв: ', cl);
WriteLn ('Цифр: ', cn);
ReadLn;
end.
Объяснение:
текстовый файл должен находиться в папке с программой, иначе укажите полный путь к нему. Кодировка файла ANSI - кириллица 1251 или OEM -русский 866.
#python v3.6.2
# dec - десятичное число, n - разрядность числа, по умолчанию - 32 (как у типа integer)
def dec_to_bin(dec, n=32):
if dec > 0:
b = ''
while dec > 0:
i = str(dec % 2)
b = i + b
dec = int(dec / 2)
return b
if dec < 0:
dec = -dec
b = ''
while dec > 0:
i = str(dec % 2)
b = i + b
dec = int(dec / 2)
# прямой код
b = '0'*(n-len(b))+b
# обратный код
b = b.replace('1', '2').replace('0', '1').replace('2', '0')
# дополнительный код
b = b[0:b.rfind('0')]+'1'+'0'*(len(b[b.rfind('0'):len(b)])-1)
return b
if dec == 0:
return 0
var
i, si, N, ss: Integer;
s: string;
begin
Write ('Введите N: ');
ReadLn (N);
s := IntToStr (N);
ss := 0;
for i := 1 to Length (s) do begin
si := StrToInt (s [i]);
if si mod 4 <> 0 then
ss := ss + si;
end;
Writeln ('Сумма цифр = ' + IntToStr (ss));
end.
// второй вариант решения
var
si, N, ss: Integer;
begin
Write ('Введите N: ');
ReadLn (N);
ss := 0;
while N > 0 do begin
si := N mod 10;
N := N div 10;
if si mod 4 <> 0 then
ss := ss + si;
end;
Writeln ('Сумма цифр = ' + IntToStr (ss));
end.