Advertisement
green1ant

oly1*2

Dec 1st, 2018
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.33 KB | None | 0 0
  1. program Project2;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils;
  7.  
  8. type
  9.    matrix = array of array [1..2] of Integer;
  10.  
  11. procedure writegoods(goods : matrix);
  12. var
  13.    i, last: integer;
  14. begin
  15.    last := high(goods);
  16.    Write('Type  :');
  17.    for i := 0 to last do
  18.       Write(goods[i][1],' ');
  19.  
  20.    Writeln;
  21.    Write('Amount:');
  22.    for i := 0 to last do
  23.       Write(goods[i][2],' ');
  24.  
  25.    Writeln;
  26. end;
  27.  
  28.  
  29. var
  30.    n, k, i, j,  last, curindex, maxindex, curelem, counter, goodslen, sum: Integer;
  31.    sweets: array of Integer;
  32.    goods: matrix;
  33.    amounts: array of Integer;
  34. begin
  35.    Writeln('Enter');
  36.    Read(n);
  37.    Readln(k);
  38.  
  39.    Writeln;
  40.    Write(n, ' ');
  41.    Writeln(k);
  42.  
  43.    SetLength(Sweets, n);
  44.    Last:= high(sweets);
  45.    for i:= 0 to Last do
  46.       Read(sweets[i]);
  47.  
  48.    Readln;
  49.  
  50.    for i:= 0 to Last do
  51.       Write(sweets[i], ' ');
  52.  
  53.    curindex:= -1;
  54.    maxindex := last;
  55.    curelem := -1;
  56.    counter :=0 ;
  57.    goodslen := 0;
  58.  
  59.    for i := 0 to last do
  60.    begin
  61.       curelem := sweets[i];
  62.       if curelem <> 0 then
  63.       begin
  64.          Inc(curindex);
  65.          SetLength(goods, goodslen + 1);
  66.          Inc(goodslen);
  67.  
  68.          counter := 0;
  69.          for j := i to last do
  70.             if sweets[j] = curelem then
  71.             begin
  72.                Inc(Counter);
  73.                sweets[j] := 0;
  74.             end;
  75.          goods[curindex][1] := curelem;
  76.          goods[curindex][2] := counter;
  77.       end;
  78.  
  79.  
  80.    end;
  81.  
  82.    last := High(goods);
  83.  
  84.    Writeln;
  85.    Writeln('-----------------------------------------------------');
  86.    {
  87.    Write('Type  :');
  88.    for i := 0 to last do
  89.       Write(goods[i][1],' ');
  90.  
  91.    Writeln;
  92.    Write('Amount:');
  93.    for i := 0 to last do
  94.       Write(goods[i][2],' ');
  95.    }
  96.    writegoods(goods);
  97.    SetLength(Amounts, Last + 1);
  98.  
  99.    for i := 0 to last do
  100.       amounts[i] := goods[i][2] div k;
  101.  
  102.    Writeln;
  103.    Writeln('For every child:');
  104.    Write('Totals:');
  105.    for i := 0 to last do
  106.       Write(amounts[i], ' ');
  107.  
  108.    sum := 0;
  109.    for i:= 0 to last do
  110.       sum := sum + amounts[i];
  111.  
  112.    Writeln;
  113.    Writeln('RESULT');
  114.    Writeln(sum);
  115.    if sum <> 0 then
  116.       for i := 0 to last do
  117.          for j := 1 to amounts[i] do
  118.             if amounts[i] <> 0 then
  119.                Write(goods[i][1], ' ')
  120.    else
  121.       Write(0);
  122.    Writeln;
  123.    Writeln('Fin');
  124.    Readln;
  125. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement