-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix.java
94 lines (93 loc) · 1.94 KB
/
Matrix.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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Java
import java.util.Scanner;
class Matrix
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int s = sc.nextInt();
int a[] = new int[s];
int b[] = new int[s];
int c[] = new int[s];
int bb[] = new int[s];
int cc[] = new int[s];
int k = 0;
int l = 0;
for(int j=0;j<s;j++)
{
a[j] = sc.nextInt();
}
int r = sc.nextInt();
/*
System.out.print("Accepted Array: ");
for(int j=0;j<s;j++)
{
System.out.print(a[j]+" ");
}
System.out.println();
*/
for(int j=0;j<s;j+=2)
{
b[k++] = a[j];
}
/*
System.out.print("b: ");
for(int j=0;j<k;j++)
{
System.out.print(b[j]+" ");
}
System.out.println();
*/
for(int j=1;j<s;j+=2)
{
c[l++] = a[j];
}
/*
System.out.print("c: ");
for(int j=0;j<l;j++)
{
System.out.print(c[j]+" ");
}
System.out.println();
*/
for(int j=0;j<k;j++)
{
if(j-r>-1)
bb[j] = b[j-r];
else
bb[j] = b[j-r+k];
}
/*
System.out.print("bb: ");
for(int j=0;j<k;j++)
{
System.out.print(bb[j]+" ");
}
System.out.println();
*/
for(int j=0;j<l;j++)
{
if(j+r<l)
cc[j] = c[j+r];
else
cc[j] = c[j+r-l];
}
/*
System.out.print("cc: ");
for(int j=0;j<l;j++)
{
System.out.print(cc[j]+" ");
}
System.out.println();
*/
k=0;
l=0;
for(int j=0;j<s;j++)
{
if(j%2==0)
System.out.print(bb[k++]+" ");
else
System.out.print(cc[l++]+" ");
}
}
}