Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

лабы / лаб5 / допы / var13

.pas
Скачиваний:
7
Добавлен:
07.06.2023
Размер:
1.02 Кб
Скачать
program var13;
var
text: string;
now_count: integer;

function makeStr(count:integer):string;
var
result: string = '';
i: integer;
begin
for i:=1 to count do result := result + '1';
makeStr := result;
end;

function replaceStr(source,destination,r:string):string;
var temp_pos: integer;
begin
temp_pos := pos(destination,source);
if (temp_pos <> 0) then
begin
delete(source,temp_pos,length(destination));
insert(r,source,temp_pos);
end;

replaceStr := source;
end;

function algorythm(s:string):string;
begin
while (pos('111',s) <> 0) do
begin
s := replaceStr(s,'111','2');
s := replaceStr(s,'222','1');
end;

algorythm := s;
end;

begin
for now_count := 50 to 100 do
begin
text := makeStr(now_count);
text := algorythm(text);

if (text = '22') then
begin
WriteLn('Наименьшее кол-во единиц: ', now_count);
break;
end;
end;
end.
Соседние файлы в папке допы