-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestClass.java
More file actions
75 lines (73 loc) · 2 KB
/
TestClass.java
File metadata and controls
75 lines (73 loc) · 2 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
72
73
74
75
class TestClass {
public int array[];
public int length;
public void sort(int[] inputArr) {
if (inputArr == null || inputArr.length == 0) {
return;
}
this.array = inputArr;
length = inputArr.length;
quickSort(0, length - 1);
}
public void quickSort(int lowerIndex, int higherIndex) {
int i = lowerIndex;
int j = higherIndex;
int pivot = array[lowerIndex+(higherIndex-lowerIndex)/2];
while (i <= j) {
while (array[i] < pivot) {
i++;
}
while (array[j] > pivot) {
j--;
}
if (i <= j) {
exchangeNumbers(i, j);
i++;
j--;
}
}
if (lowerIndex < j)
quickSort(lowerIndex, j);
if (i < higherIndex)
quickSort(i, higherIndex);
}
public int exchangeNumbers(int i, int j) {
int temp = array[i];
array[i] = array[j];
array[j] = temp;
while (temp > Integer.MAX_VALUE) {
break;
}
return temp;
}
public static void main(String args[]) throws Exception {
int K = Integer.parseInt(args[0]);
int myArray[] = FastRead.FastReadArray(args[1]);
Stopwatch st = new Stopwatch();
int n = myArray.length;
TestClass ob = new TestClass();
ob.sort(myArray);
int[] A = new int [K];
int[] B = new int [K];
for (int i = 0; i < K; i++) {
A[i] = myArray[i];
}
for (int i = n-1; i > n-K-1; i--) {
B[n-1-i] = myArray[i];
}
System.out.println(xorsum(A, B));
double time = st.elapsedTime();System.err.println("Elapsed Time: "+time+" s");
}
public static int xorsum(int[] A, int[] B) {
int[] N = A;
int[] M = B;
int sum = 0;
for (int i = 0; i < N.length; i++) {
sum = sum ^ A[i];
}
for (int i = 0; i < M.length; i++) {
sum = sum ^ B[i];
}
return sum;
}
}