var
Shop1, Shop2, Shop3, CommonProducts: TProductSet;
Product: string;
procedure ReadProducts(var Shop: TProductSet; ShopName: string);
begin
Write('Enter products for ', ShopName, ' (type "end" to finish): ');
repeat
Readln(Product);
if Product 'end' then
begin
SetLength(Shop, Length(Shop) + 1);
Shop[High(Shop)] := Product;
end;
until Product = 'end';
end;
function BuildCommonProducts(Shop1, Shop2, Shop3: TProductSet): TProductSet;
var
i, j, k: Integer;
CommonSet: TProductSet;
begin
SetLength(CommonSet, 0);
for i := 0 to High(Shop1) do
for j := 0 to High(Shop2) do
for k := 0 to High(Shop3) do
if (Shop1 = Shop2[j]) and (Shop2[j] = Shop3[k]) then
begin
SetLength(CommonSet, Length(CommonSet) + 1);
CommonSet[High(CommonSet)] := Shop1;
// Break; // Uncomment this line if you want to stop at the first common product
end;
Exit(CommonSet);
end;
procedure OutputProducts(Products: TProductSet);
var
i: Integer;
begin
Writeln('Products available in all three shops:');
for i := 0 to High(Products) do
Writeln(Products);
end;
begin
SetLength(Shop1, 0);
SetLength(Shop2, 0);
SetLength(Shop3, 0);
CommonProducts := BuildCommonProducts(Shop1, Shop2, Shop3);
OutputProducts(CommonProducts);
end.
Free Pascal Compiler version 3.2.2+dfsg-9ubuntu1 [2022/04/11] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling main.pas
Linking a.out
64 lines compiled, 0.1 sec
Enter products for Shop1 (type "end" to finish): rice beans pasta salt sugar flour tea coffee spices oil
end
end
Enter products for Shop2 (type "end" to finish): rice beans pasta salt sugar flour tea coffee spices oil
end
Enter products for Shop3 (type "end" to finish): rice beans pasta salt sugar flour tea coffee spices oil
end
Products available in all three shops:
rice beans pasta salt sugar flour tea coffee spices oil
В нормальном Pascal тип данных "множество строк" (set of string) не существует. Так что создать "множество названий продуктов" невозможно. Что ты хочешь добиться от нейросети, если сама задача абсурдна?
P.S. ChatGPT не понимает ни смысл вопроса, ни смысл ответа. Он лишь тупо комбинирует слова из вопроса и найденных в интернете по этому вопросу страниц. И надеяться на то, что ChatGPT выдаст тебе правильный код программы, по меньшей мере наивно.