File tree Expand file tree Collapse file tree 4 files changed +92
-0
lines changed Expand file tree Collapse file tree 4 files changed +92
-0
lines changed Original file line number Diff line number Diff line change 237
237
| 27 | | [ Baekjoon-1699 μ κ³±μμ ν©] ( src/DP/P1699 ) | |
238
238
| 28 | | [ Baekjoon-2225 ν©λΆν΄] ( src/DP/P2225 ) | |
239
239
240
+ ## String
241
+
242
+ | # | β | Problem | Note |
243
+ | :-: | :-: | :------------------------------------------------- | :----- |
244
+ | 01 | | [ Baekjoon-14425 λ¬Έμμ΄ μ§ν©] ( ./src/String/P14425 ) | |
245
+
240
246
---
241
247
242
248
## 2020 KAKAO BLIND RECRUITMENT
Original file line number Diff line number Diff line change
1
+ package String .P14425 ;
2
+
3
+ import java .io .*;
4
+ import java .util .*;
5
+
6
+ public class Main {
7
+
8
+ static int N , M ;
9
+
10
+ public static void main (String [] args ) throws Exception {
11
+ System .setIn (new FileInputStream ("src/String/P14425/input.txt" ));
12
+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
13
+ StringTokenizer st = new StringTokenizer (br .readLine ());
14
+
15
+ N = Integer .parseInt (st .nextToken ());
16
+ M = Integer .parseInt (st .nextToken ());
17
+
18
+ HashSet <String > hs = new HashSet <>();
19
+ while (N -- > 0 ) hs .add (br .readLine ());
20
+
21
+ int ans = 0 ;
22
+ for (int i = 0 ; i < M ; i ++)
23
+ if (hs .contains (br .readLine ())) ans ++;
24
+
25
+ System .out .println (ans );
26
+ }
27
+ }
Original file line number Diff line number Diff line change
1
+ ## [ baekjoon-14425] λ¬Έμμ΄ μ§ν©
2
+
3
+ ![ image] ( https://user-images.githubusercontent.com/22045163/102742413-2e8cc700-4398-11eb-8039-00a6f1aaa102.png )
4
+
5
+ ### λ ν¨μ¨μ μΈ μκ³ λ¦¬μ¦ μκ°νκΈ°
6
+
7
+ λ³Έ λ¬Έμ λ λμ λ¬Έμμ΄μ΄ λ¬Έμμ΄ μ§ν© λ΄μ μλμ§ μΌμΌμ΄ κ²μ¬ν΄λ³΄λ μλ°μ μλ€.
8
+
9
+ μ²μμλ λ€μκ³Ό κ°μ΄ ` O(N*M) ` μΌλ‘ νμλ€. μκ° μ νμ΄ 2μ΄μ΄κ³ ,
10
+ ` N ` κ³Ό ` M ` μ μ΅λκ°μ ` 10000 ` μ΄κΈ° λλ¬Έμ λ¬Έμ μμλ€.
11
+
12
+ ``` java
13
+ String S = new String [N ];
14
+ for (int i = 0 ; i < N ; i++ ) S [i] = br. readLine();
15
+
16
+ int ans = 0 ;
17
+ for (int i = 0 ; i < M ; i++ ) {
18
+ String s = br. readLine();
19
+ for (int j = 0 ; j < N ; j++ ) {
20
+ if (s. equals(S [j])) ans ++ ;
21
+ }
22
+ }
23
+ ```
24
+
25
+ μ΄ λ λ΅μ λ§μμΌλ μκ° ν¨μ¨μ΄ μ’μ§ μμ κ² κ°μ λ€λ₯Έ μ½λλ₯Ό μ°Έκ³ νμκ³ ,
26
+ Java Collectionsμ ** HashSet** μ μ΄μ©νλ©΄ μκ° λ³΅μ‘λλ₯Ό ν¬κ² μ€μΌ μ μλ€λ κ²μ μκ² λμλ€.
27
+
28
+ ** HashSet** μ ` Add ` , ` Contains ` μ°μ°μ μκ° λ³΅μ‘λλ λͺ¨λ ** O(1)** μ΄λ€.
29
+ λ°λΌμ λ€μκ³Ό κ°μ΄ μ½λλ₯Ό μμ±νλ©΄ λ μ’μ μ½λκ° λ μ μκ² μ§ !!
30
+
31
+ ``` java
32
+ HashSet<String > hs = new HashSet<> ();
33
+ while (N -- > 0 ) hs. add(br. readLine());
34
+
35
+ int ans = 0 ;
36
+ for (int i = 0 ; i < M ; i++ )
37
+ if (hs. contains(br. readLine())) ans ++ ;
38
+ ```
39
+
40
+ ![ image] ( https://user-images.githubusercontent.com/22045163/102742722-ec17ba00-4398-11eb-8bc9-479a07214da8.png )
41
+
42
+ μκ° λ³΅μ‘λλ₯Ό ` 2648ms ` μμ ` 424ms ` λ‘ μ€μΌ μ μλ€.
Original file line number Diff line number Diff line change
1
+ 5 11
2
+ baekjoononlinejudge
3
+ startlink
4
+ codeplus
5
+ sundaycoding
6
+ codingsh
7
+ baekjoon
8
+ codeplus
9
+ codeminus
10
+ startlink
11
+ starlink
12
+ sundaycoding
13
+ codingsh
14
+ codinghs
15
+ sondaycoding
16
+ startrink
17
+ icerink
You canβt perform that action at this time.
0 commit comments