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 | jiangly | 3640 |
2 | Benq | 3593 |
3 | tourist | 3572 |
4 | orzdevinwang | 3561 |
5 | cnnfls_csy | 3539 |
6 | ecnerwala | 3534 |
7 | Radewoosh | 3532 |
8 | gyh20 | 3447 |
9 | Rebelz | 3409 |
10 | Geothermal | 3408 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 173 |
2 | adamant | 164 |
3 | awoo | 161 |
4 | TheScrasse | 160 |
5 | nor | 159 |
6 | maroonrk | 156 |
7 | SecondThread | 152 |
8 | pajenegod | 146 |
9 | BledDest | 144 |
10 | Um_nik | 143 |
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 |
---|