Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*
- * Project: Pascal
- * User: akelix
- * Date: 20.12.18
- *)
- program products;
- Var
- inputFile : text;
- Var
- productsNeedCount, productsHasCount: integer;
- Var
- productsNeedList, productsHasList: array of integer;
- Var
- productsWeDoNotHaveList: array of integer;
- procedure ReadArray(inputFile: text; products: array of integer; count: integer);
- begin
- for var i := 0 to count - 1 do
- Read(inputFile, products[i]);
- end;
- function DoNotHaveThisItem(items: array of integer; itemWeSeek: integer): boolean;
- begin
- Result:=true;
- for var i:= 0 to items.Length - 1 do
- if items[i] = itemWeSeek then
- Result:=false;
- end;
- function FindMissedProducts(productsNeed: array of integer; productsHas: array of integer; weDoNotHaveThisProducts: array of integer): integer;
- begin
- Result:=0;
- for var i:=0 to productsNeed.Length -1 do
- if DoNotHaveThisItem(productsHas, productsNeed[i]) then
- begin
- weDoNotHaveThisProducts[Result] := productsNeed[i];
- inc(Result);
- end;
- end;
- begin
- Assign(inputFile, 'input_products.txt');
- Reset(inputFile);
- Read(inputFile, productsNeedCount, productsHasCount);
- SetLength(productsNeedList, productsNeedCount);
- SetLength(productsHasList, productsHasCount);
- SetLength(productsWeDoNotHaveList, productsNeedCount);
- ReadArray(inputFile, productsNeedList, productsNeedCount);
- ReadArray(inputFile, productsHasList, productsHasCount);
- close(inputFile);
- Println('Данные прочитаны:');
- Println(productsNeedList);
- Println(productsHasList);
- var missedItemsCount: integer = FindMissedProducts(productsNeedList, productsHasList, productsWeDoNotHaveList);
- SetLength(productsWeDoNotHaveList, missedItemsCount);
- Println('Результат:');
- if missedItemsCount > 0 then
- begin
- Print('нет, этого не хватает:');
- Println(productsWeDoNotHaveList);
- end
- else
- Println('да, все есть.');
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement