Const N = 7; // количество наименований товаров Var A:array[1..N,1..3] of integer; i,k,S:integer; Begin For i:= 1 to N do Read(A[i,1],A[i,2],A[i,3]); k:=0; For i:= N downto 1 do if A[i,2] = 0 then k:=i; if k > 0 then Begin Write('00 - ',A[k,1]*A[k,3]); S:=0; For i:= k+1 to N do if A[i,2] = 0 then Begin Write('+',A[i,1]*A[i,3]); S:=S+A[i,1]*A[i,3]; End; if S <> 0 then Write('=',S+A[k,1]*A[k,3]); WriteLn; End; k:=0; For i:= N downto 1 do if A[i,2] = 1 then k:=i; if k > 0 then Begin Write('01 - ',A[k,1]*A[k,3]); S:=0; For i:= k+1 to N do if A[i,2] = 1 then Begin Write('+',A[i,1]*A[i,3]); S:=S+A[i,1]*A[i,3]; End; if S <> 0 then Write('=',S+A[k,1]*A[k,3]); WriteLn; End; k:=0; For i:= N downto 1 do if A[i,2] = 10 then k:=i; if k > 0 then Begin Write('10 - ',A[k,1]*A[k,3]); S:=0; For i:= k+1 to N do if A[i,2] = 10 then Begin Write('+',A[i,1]*A[i,3]); S:=S+A[i,1]*A[i,3]; End; if S <> 0 then Write('=',S+A[k,1]*A[k,3]); WriteLn; End; k:=0; For i:= N downto 1 do if A[i,2] = 11 then k:=i; if k > 0 then Begin Write('11 - ',A[k,1]*A[k,3]); S:=0; For i:= k+1 to N do if A[i,2] = 11 then Begin Write('+',A[i,1]*A[i,3]); S:=S+A[i,1]*A[i,3]; End; if S <> 0 then Write('=',S+A[k,1]*A[k,3]); WriteLn; End; End.
Const N = 6; M = 7; Var A:array[1..N,1..M] of integer; i,j,k,MM,B:integer; Begin Randomize; WriteLn('Исходный массив:'); For i:= 1 to N do Begin For j:= 1 to M do Begin A[i,j]:=random(21)-10; Write(A[i,j]:3,' ') End; WriteLn End; WriteLn; WriteLn('Отсортированный массив:'); For i:= 1 to N do Begin For j:= 1 to M do Begin MM:=j; if i mod 2 = 0 then Begin For k:= j+1 to M do if A[i,MM] > A[i,k] then MM:=k End else For k:= j+1 to M do if A[i,MM] < A[i,k] then MM:=k; B:=A[i,MM]; A[i,MM]:=A[i,j]; A[i,j]:=B; Write(A[i,j]:3,' ') End; WriteLn End End.
N = 7; // количество наименований товаров
Var
A:array[1..N,1..3] of integer;
i,k,S:integer;
Begin
For i:= 1 to N do
Read(A[i,1],A[i,2],A[i,3]);
k:=0;
For i:= N downto 1 do
if A[i,2] = 0 then k:=i;
if k > 0 then
Begin
Write('00 - ',A[k,1]*A[k,3]);
S:=0;
For i:= k+1 to N do
if A[i,2] = 0 then
Begin
Write('+',A[i,1]*A[i,3]);
S:=S+A[i,1]*A[i,3];
End;
if S <> 0 then Write('=',S+A[k,1]*A[k,3]);
WriteLn;
End;
k:=0;
For i:= N downto 1 do
if A[i,2] = 1 then k:=i;
if k > 0 then
Begin
Write('01 - ',A[k,1]*A[k,3]);
S:=0;
For i:= k+1 to N do
if A[i,2] = 1 then
Begin
Write('+',A[i,1]*A[i,3]);
S:=S+A[i,1]*A[i,3];
End;
if S <> 0 then Write('=',S+A[k,1]*A[k,3]);
WriteLn;
End;
k:=0;
For i:= N downto 1 do
if A[i,2] = 10 then k:=i;
if k > 0 then
Begin
Write('10 - ',A[k,1]*A[k,3]);
S:=0;
For i:= k+1 to N do
if A[i,2] = 10 then
Begin
Write('+',A[i,1]*A[i,3]);
S:=S+A[i,1]*A[i,3];
End;
if S <> 0 then Write('=',S+A[k,1]*A[k,3]);
WriteLn;
End;
k:=0;
For i:= N downto 1 do
if A[i,2] = 11 then k:=i;
if k > 0 then
Begin
Write('11 - ',A[k,1]*A[k,3]);
S:=0;
For i:= k+1 to N do
if A[i,2] = 11 then
Begin
Write('+',A[i,1]*A[i,3]);
S:=S+A[i,1]*A[i,3];
End;
if S <> 0 then Write('=',S+A[k,1]*A[k,3]);
WriteLn;
End;
End.
Пример работы программы:
17 1 2
3 0 5
7 1 4
8 11 9
95 0 3
31 10 44
5 1 6
00 - 15+285=300
01 - 34+28+30=92
10 - 1364
11 - 72
N = 6;
M = 7;
Var
A:array[1..N,1..M] of integer;
i,j,k,MM,B:integer;
Begin
Randomize;
WriteLn('Исходный массив:');
For i:= 1 to N do
Begin
For j:= 1 to M do
Begin
A[i,j]:=random(21)-10;
Write(A[i,j]:3,' ')
End;
WriteLn
End;
WriteLn;
WriteLn('Отсортированный массив:');
For i:= 1 to N do
Begin
For j:= 1 to M do
Begin
MM:=j;
if i mod 2 = 0 then
Begin
For k:= j+1 to M do
if A[i,MM] > A[i,k] then MM:=k
End
else
For k:= j+1 to M do
if A[i,MM] < A[i,k] then MM:=k;
B:=A[i,MM];
A[i,MM]:=A[i,j];
A[i,j]:=B;
Write(A[i,j]:3,' ')
End;
WriteLn
End
End.
Пример работы программы:
Исходный массив:
9 -5 6 0 -9 0 9
3 -9 -4 10 -8 10 3
-2 1 2 3 3 0 10
-10 1 8 -3 -4 -3 4
-9 -7 -3 -9 2 -1 -3
7 -10 10 -3 4 10 0
Отсортированный массив:
9 9 6 0 0 -5 -9
-9 -8 -4 3 3 10 10
10 3 3 2 1 0 -2
-10 -4 -3 -3 1 4 8
2 -1 -3 -3 -7 -9 -9
-10 -3 0 4 7 10 10