Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project2;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- type
- matrix = array of array [1..2] of Integer;
- procedure writegoods(goods : matrix);
- var
- i, last: integer;
- begin
- last := high(goods);
- Write('Type :');
- for i := 0 to last do
- Write(goods[i][1],' ');
- Writeln;
- Write('Amount:');
- for i := 0 to last do
- Write(goods[i][2],' ');
- Writeln;
- end;
- var
- n, k, i, j, last, curindex, maxindex, curelem, counter, goodslen, sum: Integer;
- sweets: array of Integer;
- goods: matrix;
- amounts: array of Integer;
- begin
- Writeln('Enter');
- Read(n);
- Readln(k);
- Writeln;
- Write(n, ' ');
- Writeln(k);
- SetLength(Sweets, n);
- Last:= high(sweets);
- for i:= 0 to Last do
- Read(sweets[i]);
- Readln;
- for i:= 0 to Last do
- Write(sweets[i], ' ');
- curindex:= -1;
- maxindex := last;
- curelem := -1;
- counter :=0 ;
- goodslen := 0;
- for i := 0 to last do
- begin
- curelem := sweets[i];
- if curelem <> 0 then
- begin
- Inc(curindex);
- SetLength(goods, goodslen + 1);
- Inc(goodslen);
- counter := 0;
- for j := i to last do
- if sweets[j] = curelem then
- begin
- Inc(Counter);
- sweets[j] := 0;
- end;
- goods[curindex][1] := curelem;
- goods[curindex][2] := counter;
- end;
- end;
- last := High(goods);
- Writeln;
- Writeln('-----------------------------------------------------');
- {
- Write('Type :');
- for i := 0 to last do
- Write(goods[i][1],' ');
- Writeln;
- Write('Amount:');
- for i := 0 to last do
- Write(goods[i][2],' ');
- }
- writegoods(goods);
- SetLength(Amounts, Last + 1);
- for i := 0 to last do
- amounts[i] := goods[i][2] div k;
- Writeln;
- Writeln('For every child:');
- Write('Totals:');
- for i := 0 to last do
- Write(amounts[i], ' ');
- sum := 0;
- for i:= 0 to last do
- sum := sum + amounts[i];
- Writeln;
- Writeln('RESULT');
- Writeln(sum);
- if sum <> 0 then
- for i := 0 to last do
- for j := 1 to amounts[i] do
- if amounts[i] <> 0 then
- Write(goods[i][1], ' ')
- else
- Write(0);
- Writeln;
- Writeln('Fin');
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement