-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpiral.java
More file actions
66 lines (66 loc) · 1.65 KB
/
Spiral.java
File metadata and controls
66 lines (66 loc) · 1.65 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
import java.util.*;
public class Spiral {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
int ar[][]=new int[N][N];
for(int x=0;x<N;x++){
for(int y=0;y<N;y++){
ar[x][y]=sc.nextInt();
}
}
int A=0;
// int B=n-1;
// int C=n-1;
// int D=0;
for(int n=N;n>=1;n--){
int count=0;
while(true){
if(A!=n-1){
System.out.println(ar[0][A]);
A++;
count++;
}
if(count==n){
break;
}
}
A=1;
count=0;
while(true){
if(A!=n-1){
System.out.println(ar[A][n-1]);
A++;
count++;
}
if(count==n-1){
break;
}
}
A=n-2;
count=0;
while(true){
if(A!=0){
System.out.println(ar[n-1][A]);
A--;
count++;
}
if(count==n-1){
break;
}
}
A=n-1;
count=0;
while(true){
if(A!=1){
System.out.println(ar[0][A]);
A--;
count++;
}
if(count==n-1){
break;
}
}
}
}
}