This repository was archived by the owner on Dec 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBOJ11728.java
More file actions
66 lines (56 loc) · 1.9 KB
/
Copy pathBOJ11728.java
File metadata and controls
66 lines (56 loc) · 1.9 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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BOJ11728 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
int[] array1 = new int[n];
int[] array2 = new int[m];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
array1[i] = Integer.parseInt(st.nextToken());
}
st = new StringTokenizer(br.readLine());
for (int i = 0; i < m; i++) {
array2[i] = Integer.parseInt(st.nextToken());
}
int index1 = 0;
int index2 = 0;
int index3 = 0;
int[] answerArray = new int[n + m];
while (index1 <= n && index2 <= m) {
if (index1 == n && index2 == m) {
break;
}
if (index1 == n) {
answerArray[index3] = array2[index2];
index2++;
index3++;
continue;
}
if (index2 == m) {
answerArray[index3] = array1[index1];
index1++;
index3++;
continue;
}
if (array1[index1] <= array2[index2]) {
answerArray[index3] = array1[index1];
index1++;
}
else {
answerArray[index3] = array2[index2];
index2++;
}
index3++;
}
for (int i = 0; i < n + m; i++) {
System.out.print(answerArray[i] + " ");
}
System.out.println();
}
}