Помогите перевести код из Pascal в С++

var A:array[1..100,1..100] of integer;
         n,m,i,j: integer;
         c: integer;
begin
         readln(n,m);
   c:=1;
   for j:=1 to m do
   begin
         for i:=1 to n do
      begin
         A[i,j]:=c;
         if (j mod 2 = 0) and (i<>n) then
                  dec(c)
         else
                  inc(c);
      end;
      c:=c+n-1;
   end;
   for i:=1 to n do
   begin
         for j:=1 to m do
               write(A[i,j]:5);
      writeln;
   end;
   readln;
end.

Ответы (1 шт):

Автор решения: pagislav
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector< vector<int> > arr(n,vector<int>(m));

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            cin >> arr[i][j];

    for (int j = 0; j < m; ++j)
    {
        if (j)
            for (int i = n-1; i >= 0; --i)
                cout << arr[i][j] << ' ';
        else
            for (int i = 0; i < n; ++i)
                cout << arr[i][j] << ' ';

        cout << endl;
    }
    return 0;
}

Насколько я понял, исходя из комментария, это то, что вам нужно. Пример работы:

Входные данные:

3 3
1 2 3
4 5 6
7 8 9

Выходные:

1 4 7 
8 5 2 
9 6 3 
→ Ссылка