#include<bits/stdc++.h>
using namespace std;
void rotate(vector < vector < int >> & matrix) {
int n = matrix.size();
//transposing the matrix
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
swap(matrix[i][j], matrix[j][i]);
}
}
//reversing each row of the matrix
for (int i = 0; i < n; i++) {
reverse(matrix[i].begin(), matrix[i].end());
}
}
int main() {
vector < vector < int >> arr;
arr = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
rotate(arr);
cout << "Rotated Image" << endl;
for (int i = 0; i < arr.size(); i++) {
for (int j = 0; j < arr[0].size(); j++) {
cout << arr[i][j] << " ";
}
cout << "n";
}
}
CiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp2b2lkIHJvdGF0ZSh2ZWN0b3IgPCB2ZWN0b3IgPCBpbnQgPj4gJiBtYXRyaXgpIHsKICAgIGludCBuID0gbWF0cml4LnNpemUoKTsKICAgIC8vdHJhbnNwb3NpbmcgdGhlIG1hdHJpeAogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgIGZvciAoaW50IGogPSAwOyBqIDwgaTsgaisrKSB7CiAgICAgICAgc3dhcChtYXRyaXhbaV1bal0sIG1hdHJpeFtqXVtpXSk7CiAgICB9CiAgICB9CiAgICAvL3JldmVyc2luZyBlYWNoIHJvdyBvZiB0aGUgbWF0cml4CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewogICAgcmV2ZXJzZShtYXRyaXhbaV0uYmVnaW4oKSwgbWF0cml4W2ldLmVuZCgpKTsKICAgIH0KfQoKaW50IG1haW4oKSB7CiAgICB2ZWN0b3IgPCB2ZWN0b3IgPCBpbnQgPj4gYXJyOwogICAgYXJyID0gIHt7MSwgMiwgM30sIHs0LCA1LCA2fSwgezcsIDgsIDl9fTsKICAgIHJvdGF0ZShhcnIpOwogICAgY291dCA8PCAiUm90YXRlZCBJbWFnZSIgPDwgZW5kbDsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgYXJyLnNpemUoKTsgaSsrKSB7CiAgICBmb3IgKGludCBqID0gMDsgaiA8IGFyclswXS5zaXplKCk7IGorKykgewogICAgICAgIGNvdXQgPDwgYXJyW2ldW2pdIDw8ICIgIjsKICAgIH0KICAgIGNvdXQgPDwgIm4iOwogICAgfQoKfQoK