Skip to content

Commit dfe0930

Browse files
committed
feat(1920) : add code(Stream 형태) / Title : 수 찾기
- 시간 초과로 인해 이진탐색으로 풀것
1 parent aff5844 commit dfe0930

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

백준/TO/1920/App.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import java.io.*;
2+
import java.util.*;
3+
import java.util.stream.*;
4+
5+
public class App {
6+
public static void main(String[] args) throws IOException {
7+
/*
8+
* 1920번
9+
* 자료 구조
10+
* 정렬
11+
* 이분 탐색
12+
*/
13+
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
14+
BufferedReader br = new BufferedReader(new FileReader("1920/input.txt"));
15+
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
16+
int[] ll = { 0 };
17+
int[][] arys = new int[2][];
18+
br.lines()
19+
.filter(s -> ll[0]++ % 2 != 0)
20+
.limit(2)
21+
.map(l -> Arrays.stream(l.split(" ")).mapToInt(Integer::parseInt).toArray())
22+
.forEach(arr -> {
23+
if (arys[0] == null) {
24+
arys[0] = arr;
25+
} else {
26+
arys[1] = arr;
27+
Arrays.stream(arys[1])
28+
.mapToLong(i -> IntStream.of(arys[0]).anyMatch(i2 -> i2 == i) ? 1 : 0)
29+
.forEach(r -> {
30+
try {
31+
bw.write(r + "\n");
32+
} catch (IOException e) {
33+
}
34+
});
35+
}
36+
});
37+
bw.flush();
38+
bw.close();
39+
br.close();
40+
}
41+
}

백준/TO/1920/input.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
5
2+
4 1 5 2 3
3+
5
4+
1 3 7 9 5

0 commit comments

Comments
 (0)