По разделам

 

Решение задачи 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 Просмотров: 12039
Matrix 2 Просмотров: 4481
Matrix 3 Просмотров: 4611
Matrix 4 Просмотров: 3484
Matrix 5 Просмотров: 5122
Matrix 6 Просмотров: 3445
Matrix 7 Просмотров: 4226
Matrix 8 Просмотров: 3249
Matrix 9 Просмотров: 4087
Matrix 10 Просмотров: 2970
Matrix 11 Просмотров: 4424
Matrix 12 Просмотров: 3120
Matrix 13 Просмотров: 3085
Matrix 14 Просмотров: 2021
Matrix 15 Просмотров: 2728
Matrix 16 Просмотров: 2621
Matrix 17 Просмотров: 4447
Matrix 18 Просмотров: 2248
Matrix 19 Просмотров: 2921
Matrix 20 Просмотров: 3346
Matrix 21 Просмотров: 3344
Matrix 22 Просмотров: 2045
Matrix 23 Просмотров: 4552
Matrix 24 Просмотров: 2268
Matrix 25 Просмотров: 2514
Matrix 26 Просмотров: 2142
Matrix 27 Просмотров: 2089
Matrix 28 Просмотров: 1980
Matrix 29 Просмотров: 1892
Matrix 30 Просмотров: 1841
Matrix 31 Просмотров: 1558
Matrix 32 Просмотров: 1437
Matrix 33 Просмотров: 1531
Matrix 34 Просмотров: 1897
Matrix 35 Просмотров: 1618
Matrix 36 Просмотров: 1671
Matrix 37 Просмотров: 1426
Matrix 38 Просмотров: 1535
Matrix 39 Просмотров: 1428
Matrix 40 Просмотров: 1476
Matrix 41 Просмотров: 1187
Matrix 42 Просмотров: 1535
Matrix 43 Просмотров: 1209
Matrix 44 Просмотров: 1210
Matrix 45 Просмотров: 1268
Matrix 46 Просмотров: 1308
Matrix 47 Просмотров: 1487
Matrix 48 Просмотров: 1293
Matrix 49 Просмотров: 1278
Matrix 50 Просмотров: 1610
Matrix 51 Просмотров: 1446
Matrix 52 Просмотров: 1435
Matrix 53 Просмотров: 1310
Matrix 54 Просмотров: 1060
Matrix 55 Просмотров: 1142
Matrix 56 Просмотров: 941
Matrix 57 Просмотров: 1116
Matrix 58 Просмотров: 1391
Matrix 59 Просмотров: 1159
Matrix 60 Просмотров: 1057
Matrix 61 Просмотров: 1101
Matrix 62 Просмотров: 1084
Matrix 63 Просмотров: 1246
Matrix 64 Просмотров: 1236
Matrix 65 Просмотров: 1113
Matrix 66 Просмотров: 971
Matrix 67 Просмотров: 1001
Matrix 68 Просмотров: 1091
Matrix 69 Просмотров: 969
Matrix 70 Просмотров: 1086
Matrix 71 Просмотров: 927
Matrix 72 Просмотров: 954
Matrix 73 Просмотров: 1019
Matrix 74 Просмотров: 1000
Matrix 75 Просмотров: 882
Matrix 76 Просмотров: 1003
Matrix 77 Просмотров: 1029
Matrix 78 Просмотров: 960
Matrix 79 Просмотров: 1014
Matrix 80 Просмотров: 2614
Matrix 81 Просмотров: 1373
Matrix 82 Просмотров: 1103
Matrix 83 Просмотров: 1469
Matrix 84 Просмотров: 966
Matrix 85 Просмотров: 1040
Matrix 86 Просмотров: 960
Matrix 87 Просмотров: 1061
Matrix 88 Просмотров: 884
Matrix 89 Просмотров: 887
Matrix 90 Просмотров: 1032
Matrix 91 Просмотров: 911
Matrix 92 Просмотров: 892
Matrix 93 Просмотров: 887
Matrix 94 Просмотров: 1060
Matrix 95 Просмотров: 885
Matrix 96 Просмотров: 961
Matrix 97 Просмотров: 990
Matrix 98 Просмотров: 1159
Matrix 99 Просмотров: 1095
Matrix 100 Просмотров: 1217

Комментарии

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



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