-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzigzag.java
31 lines (30 loc) · 824 Bytes
/
zigzag.java
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
import java.util.*;
import java.lang.*;
class Test{
public static void main(String e[]){
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int si=n*2-1;
ArrayList<Integer>[] li= new ArrayList[10];
int i=0,j=0,sm=0;
for(i=0;i<10;i++)
li[i]=new ArrayList<Integer>();
int a[][]= new int[n][m];
for(i=0;i<n;i++)
for(j=0;j<m;j++)
a[i][j]=sc.nextInt();
for(i=0;i<n;i++){
for(j=0;j<m;j++){
sm=i+j;
if(sm%2==0)
li[sm].add(0,a[i][j]);
else
li[sm].add(a[i][j]);
}
}
for(i=0;i<10;i++)
for(j=0;j<li[i].size();j++)
System.out.print(li[i].get(j)+" ");
}
}