По разделам

 

Решение задачи Matrix 76


Дана матрица размера M ×N. Упорядочить ее строки так, чтобы их первые элементы образовывали возрастающую последовательность.

Код (C/C++)

#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int m, n;
    cout << "N: ";
    cin >> n;

    cout << "M: ";
    cin >> m;
    int a[10][10];

    int i,j;
    for (i=1; i<=m; ++i){
        cout<<i<<" : "<<endl;
        for (j=1; j<=n; ++j){
            cout<<j<<" : ";
            cin >> a[i][j];
        }
    }

    int m2=m,i2;
    for (i=1; i<m; ++i){
        i2=1;
        --m2;
        while (i2<=m2){
            if (a[i2][1]>a[i2+1][1])
                for (j=1;j<=n; ++j) {
                    a[i2][j]+=a[i2+1][j];
                    a[i2+1][j]=a[i2][j]-a[i2+1][j];
                    a[i2][j]=a[i2][j]-a[i2+1][j];
                }
            ++i2;
        }
    }

    for (i=1; i<=m; ++i){

        for (j=1; j<=n; ++j){
            cout<<" : "<<a[i][j];

        }
        cout<<" : "<<endl;
    }
    return 0;

}

Код (Pascal)

program Matrix76;
type
  matrix = array [1..10,1..10] of integer;
 
var
  a:matrix;
  M, M2, N, i, i2, j:Integer;
 
procedure Swap(var X,Y:Integer);
begin
 if x<>y then
  begin
   X:=X+Y;
   Y:=X-Y;
   X:=X-Y;
  end;
end;
 
procedure SwapMatrixRow(var mat:matrix; X,Y:Integer);
var
 j:integer;
begin
 if x<>y then
  for j:=1 to N do
   swap(mat[x,j], mat[y,j]);
end;
 
 
begin
 Write('N: ');
 Readln(N);
 Write('M: ');
 Readln(M);
 
 for  i:=1 to M do
  begin
   writeln(i,': ');
   for j:=1 to N do
    begin
     Write(j,' : ');
     Read(a[i,j]);
    end;
  end;
 
 M2:=M;
 for i:=1 to M-1 do
  begin
   i2:=1;
   M2:=M2-1;
   while (i2<=M2) do     begin      if a[i2,1]>a[i2+1,1] then
      begin
       SwapMatrixRow(a, i2, i2+1);
      end;
     inc(i2);
    end;
   end;
 
 for  i:=1 to M do
  begin
   for j:=1 to N do
    begin
     Write(' : ',a[i,j]);
    end;
   writeln(' : ');
  end;
end.
									




Matrix. Абрамян
Matrix 1 Просмотров: 11747
Matrix 2 Просмотров: 4310
Matrix 3 Просмотров: 4443
Matrix 4 Просмотров: 3320
Matrix 5 Просмотров: 4968
Matrix 6 Просмотров: 3299
Matrix 7 Просмотров: 4057
Matrix 8 Просмотров: 3091
Matrix 9 Просмотров: 3972
Matrix 10 Просмотров: 2828
Matrix 11 Просмотров: 4291
Matrix 12 Просмотров: 2994
Matrix 13 Просмотров: 2940
Matrix 14 Просмотров: 1889
Matrix 15 Просмотров: 2573
Matrix 16 Просмотров: 2461
Matrix 17 Просмотров: 4293
Matrix 18 Просмотров: 2113
Matrix 19 Просмотров: 2774
Matrix 20 Просмотров: 3189
Matrix 21 Просмотров: 3212
Matrix 22 Просмотров: 1945
Matrix 23 Просмотров: 4426
Matrix 24 Просмотров: 2174
Matrix 25 Просмотров: 2346
Matrix 26 Просмотров: 2021
Matrix 27 Просмотров: 1984
Matrix 28 Просмотров: 1883
Matrix 29 Просмотров: 1794
Matrix 30 Просмотров: 1741
Matrix 31 Просмотров: 1476
Matrix 32 Просмотров: 1341
Matrix 33 Просмотров: 1436
Matrix 34 Просмотров: 1770
Matrix 35 Просмотров: 1496
Matrix 36 Просмотров: 1575
Matrix 37 Просмотров: 1311
Matrix 38 Просмотров: 1405
Matrix 39 Просмотров: 1332
Matrix 40 Просмотров: 1353
Matrix 41 Просмотров: 1102
Matrix 42 Просмотров: 1447
Matrix 43 Просмотров: 1118
Matrix 44 Просмотров: 1120
Matrix 45 Просмотров: 1160
Matrix 46 Просмотров: 1218
Matrix 47 Просмотров: 1384
Matrix 48 Просмотров: 1172
Matrix 49 Просмотров: 1198
Matrix 50 Просмотров: 1516
Matrix 51 Просмотров: 1355
Matrix 52 Просмотров: 1341
Matrix 53 Просмотров: 1200
Matrix 54 Просмотров: 987
Matrix 55 Просмотров: 1053
Matrix 56 Просмотров: 847
Matrix 57 Просмотров: 1030
Matrix 58 Просмотров: 1277
Matrix 59 Просмотров: 1050
Matrix 60 Просмотров: 975
Matrix 61 Просмотров: 1007
Matrix 62 Просмотров: 993
Matrix 63 Просмотров: 1142
Matrix 64 Просмотров: 1143
Matrix 65 Просмотров: 1015
Matrix 66 Просмотров: 858
Matrix 67 Просмотров: 890
Matrix 68 Просмотров: 996
Matrix 69 Просмотров: 871
Matrix 70 Просмотров: 990
Matrix 71 Просмотров: 824
Matrix 72 Просмотров: 865
Matrix 73 Просмотров: 942
Matrix 74 Просмотров: 897
Matrix 75 Просмотров: 791
Matrix 76 Просмотров: 910
Matrix 77 Просмотров: 934
Matrix 78 Просмотров: 871
Matrix 79 Просмотров: 921
Matrix 80 Просмотров: 2498
Matrix 81 Просмотров: 1265
Matrix 82 Просмотров: 973
Matrix 83 Просмотров: 1366
Matrix 84 Просмотров: 872
Matrix 85 Просмотров: 947
Matrix 86 Просмотров: 876
Matrix 87 Просмотров: 963
Matrix 88 Просмотров: 780
Matrix 89 Просмотров: 789
Matrix 90 Просмотров: 947
Matrix 91 Просмотров: 813
Matrix 92 Просмотров: 777
Matrix 93 Просмотров: 799
Matrix 94 Просмотров: 947
Matrix 95 Просмотров: 781
Matrix 96 Просмотров: 882
Matrix 97 Просмотров: 896
Matrix 98 Просмотров: 1041
Matrix 99 Просмотров: 1016
Matrix 100 Просмотров: 1127

Комментарии

Чтобы написать комментарии вам нужно войти в систему или зарегистрироваться



Заявка на расчет