Given a square matrix mat[][] of size N x N. The task is to rotate it by 90 degrees in anti-clockwise direction without using any extra space.
Problem Link
if anyone could look at my code and tell where am I going wrong, PLEASE
code
# | User | Rating |
---|---|---|
1 | tourist | 3757 |
2 | jiangly | 3647 |
3 | Benq | 3581 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | Radewoosh | 3509 |
8 | ecnerwala | 3486 |
9 | jqdai0815 | 3474 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 171 |
2 | awoo | 165 |
3 | adamant | 163 |
4 | TheScrasse | 159 |
5 | maroonrk | 155 |
6 | nor | 154 |
7 | -is-this-fft- | 152 |
8 | Petr | 147 |
9 | orz | 145 |
9 | pajenegod | 145 |
Given a square matrix mat[][] of size N x N. The task is to rotate it by 90 degrees in anti-clockwise direction without using any extra space.
Problem Link
if anyone could look at my code and tell where am I going wrong, PLEASE
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define LL long long
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define pr(v) pair<v,v>
#define pb push_back
#define FOR(i, j, k) for (auto i=j ; i<k ; i++)
#define ROF(i, j, k) for (auto i=j ; i>=k ; i--)
const long long INF = 1e18;
const long long MAX = 2e5+10;
int main() {
fastio;
int t=1; cin>>t;
while (t--) {
int n; cin>>n; int a[n][n];
FOR(i, 0, n) FOR(j, 0, n) cin>>a[i][j];
FOR(k, 0, n) {
int i=k, j=0, p=n-1-k, q=p-i, temp;
while (q-- && i<p) {
temp=a[i][i];
while (j<=p) {
swap(temp, a[j][i]);j++;
}j=i+1;
while (j<=p) {
swap(temp, a[p][j]);j++;
}j=p-1;
while (j>=i) {
swap(temp, a[j][p]); j--;
}j=p-1;
while (j>=i) {
swap(temp, a[i][j]); j--;
}
j=i;
}
}
FOR(i,0,n) {
FOR(j,0,n) cout<<a[i][j]<<" ";
cout<<"\n";
}
}
}
Name |
---|