This repository was archived by the owner on Apr 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdummy.java
More file actions
48 lines (44 loc) · 1.38 KB
/
Copy pathdummy.java
File metadata and controls
48 lines (44 loc) · 1.38 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
import java.util.Scanner;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.io.File;
import java.util.*;
public class dummy {
static int binarySearch(int[] array, int value, int low, int high) {
int mid;
if (high < low) {
return -1;
} else {
mid = (low + high) / 2;
if (array[mid] > value) {
return binarySearch(array, value, low, mid-1);
} else if (array[mid] < value) {
return binarySearch(array, value, mid + 1, high);
} else {
return mid;
}
}
}
public static void main(String[] args) {
try {
File file = new File("out.txt"); // Your file
FileOutputStream fos = new FileOutputStream(file);
PrintStream ps = new PrintStream(fos);
System.setOut(ps);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Scanner sc = new Scanner(System.in);
int i, value, answer;
int[] array = new int[10000];
for (i = 0; i < 10000; i++) {
array[i] = sc.nextInt();
}
for (i = 0; i < 10000; i++) {
value = sc.nextInt();
answer = binarySearch(array, value, 0, 9999);
System.out.printf("%d\n", answer);
}
}
}