#include <iostream>
#include <iomanip>
using namespace std;
void transpose(double **matrix, int size, double **result)
{
for (int i = 0; i < size; i++)
for (int j = 0; j < size; j++)
result[j][i] = matrix[i][j];
}
void print(double **matrix, int size)
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
cout << setw(2) << matrix[i][j] << ' ';
cout << endl;
}
cout << endl;
}
int main()
{
double **matrix, **result;
int size = 4;
matrix = new double*[size];
result = new double*[size];
int cnt = 1;
for (int i = 0; i < size; i++)
{
matrix[i] = new double[size];
result[i] = new double[size];
for (int j = 0; j < size; j++)
matrix[i][j] = cnt++;
}
transpose(matrix, size, result);
print(matrix, size);
print(result, size);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aW9tYW5pcD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp2b2lkIHRyYW5zcG9zZShkb3VibGUgKiptYXRyaXgsIGludCBzaXplLCBkb3VibGUgKipyZXN1bHQpCnsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgc2l6ZTsgaSsrKQogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgc2l6ZTsgaisrKQogICAgICAgICAgICByZXN1bHRbal1baV0gPSBtYXRyaXhbaV1bal07Cn0KCnZvaWQgcHJpbnQoZG91YmxlICoqbWF0cml4LCBpbnQgc2l6ZSkKewogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBzaXplOyBpKyspCiAgICB7CiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBzaXplOyBqKyspCiAgICAgICAgICAgIGNvdXQgPDwgc2V0dygyKSA8PCBtYXRyaXhbaV1bal0gPDwgJyAnOwogICAgICAgIGNvdXQgPDwgZW5kbDsKICAgIH0KCiAgICBjb3V0IDw8IGVuZGw7Cn0KCmludCBtYWluKCkKewogICAgZG91YmxlICoqbWF0cml4LCAqKnJlc3VsdDsKICAgIGludCBzaXplID0gNDsKCiAgICBtYXRyaXggPSBuZXcgZG91YmxlKltzaXplXTsKICAgIHJlc3VsdCA9IG5ldyBkb3VibGUqW3NpemVdOwoKICAgIGludCBjbnQgPSAxOwoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgc2l6ZTsgaSsrKQogICAgewogICAgICAgIG1hdHJpeFtpXSA9IG5ldyBkb3VibGVbc2l6ZV07CiAgICAgICAgcmVzdWx0W2ldID0gbmV3IGRvdWJsZVtzaXplXTsKCiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBzaXplOyBqKyspCiAgICAgICAgICAgIG1hdHJpeFtpXVtqXSA9IGNudCsrOwogICAgfQoKICAgIHRyYW5zcG9zZShtYXRyaXgsIHNpemUsIHJlc3VsdCk7CgogICAgcHJpbnQobWF0cml4LCBzaXplKTsKICAgIHByaW50KHJlc3VsdCwgc2l6ZSk7CiAgICAKICAgIHJldHVybiAwOwp9