-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix Rotation
More file actions
71 lines (53 loc) · 1.45 KB
/
Copy pathMatrix Rotation
File metadata and controls
71 lines (53 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void rotate(int N[][],int n)
{
int a=0,b=0,c=0,d=0,j=0,i=0,t1=0,t2=0,jl=n-1;
for(j=0;j<n/2;j++)
{
a=i;
b=i;
c=n-i-1;
d=n-i-1;
while(a<=n-i-2)
{
t1 = N[b][jl];
N[b][jl]= N[j][a];
t2=N[jl][c];
N[jl][c] = t1;
N[j][a] = N[d][j];
N[d][j] = t2;
++a;++b;--c;--d;
}
++i;
--jl;
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int N [] [] = new int [n] [n] ;
int i=0,j=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
N[i][j] = in.nextInt();
}
}
System.out.println("Rotating by 90");
rotate(N,n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(N[i][j]+" ");
}
System.out.println("");
}
}
}