forked from satnaing/astro-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Affected files: .obsidian/workspace.json src/content/blog/boj-14425-문자열-집합.md
- Loading branch information
Showing
2 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,24 @@ | |
} | ||
} | ||
] | ||
}, | ||
{ | ||
"id": "f050f861ca13820a", | ||
"type": "tabs", | ||
"children": [ | ||
{ | ||
"id": "5aacb1a472f91ae8", | ||
"type": "leaf", | ||
"state": { | ||
"type": "markdown", | ||
"state": { | ||
"file": "src/content/blog/boj-14425-문자열-집합.md", | ||
"mode": "source", | ||
"source": false | ||
} | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"direction": "vertical" | ||
|
@@ -86,7 +104,7 @@ | |
"state": { | ||
"type": "backlink", | ||
"state": { | ||
"file": "src/content/blog/boj-5014-스타트링크.md", | ||
"file": "src/content/blog/boj-14425-문자열-집합.md", | ||
"collapseAll": false, | ||
"extraContext": false, | ||
"sortOrder": "alphabetical", | ||
|
@@ -103,7 +121,7 @@ | |
"state": { | ||
"type": "outgoing-link", | ||
"state": { | ||
"file": "src/content/blog/boj-5014-스타트링크.md", | ||
"file": "src/content/blog/boj-14425-문자열-집합.md", | ||
"linksCollapsed": false, | ||
"unlinkedCollapsed": true | ||
} | ||
|
@@ -126,7 +144,7 @@ | |
"state": { | ||
"type": "outline", | ||
"state": { | ||
"file": "src/content/blog/boj-5014-스타트링크.md" | ||
"file": "src/content/blog/boj-14425-문자열-집합.md" | ||
} | ||
} | ||
} | ||
|
@@ -149,8 +167,10 @@ | |
"table-editor-obsidian:Advanced Tables Toolbar": false | ||
} | ||
}, | ||
"active": "0f0fd716299d38e2", | ||
"active": "5aacb1a472f91ae8", | ||
"lastOpenFiles": [ | ||
"src/content/blog/boj-5014-스타트링크.md", | ||
"src/content/blog/boj-14425-문자열-집합.md", | ||
"dist/assets/[email protected]", | ||
"dist/assets/forrest-gump-quote.webp.jpg", | ||
"dist/_astro/[email protected]", | ||
|
@@ -171,8 +191,6 @@ | |
"dist/posts/우테코-2차-소감문.png", | ||
"dist/posts/우테코-1차-소감문.png", | ||
"dist/posts/virtual-lans.png", | ||
"dist/posts/windows에서-wsl을-완전히-삭제하자.png", | ||
"src/content/blog/boj-5014-스타트링크.md", | ||
"src/content/blog/boj-11725-트리의-부모-찾기.md", | ||
"src/content/blog/boj-1935-후위-표기식2.md", | ||
"src/content/blog/boj-15666-N과-M-(12).md", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
author: Gyunseo Lee | ||
title: "BOJ 백준 14425: 문자열 집합" | ||
pubDatetime: 2024-05-23T22:42:00+09:00 | ||
modDatetime: 2024-05-23T22:42:00+09:00 | ||
featured: false | ||
draft: false | ||
tags: | ||
- PS | ||
- Algorithms | ||
- BOJ | ||
- 실랜디 | ||
- HashMap | ||
description: HashMap 자료구조인 Set을 잘 활용하자! | ||
ogImage: "" | ||
--- | ||
|
||
## Table of contents | ||
|
||
## 들어가며 | ||
|
||
이 문제는 파이썬의 HashMap 자료구조인 `set` 객체를 사용하여 풀면 됩니다. | ||
`set` 객체를 쓰면 정말 쉽게 풀 수 있습니다. | ||
그래도 이왕 문제 푸는 김에 뭔가를 얻어 가면 좋겠죠? | ||
그래서 `set` 객체가 왜 HashMap 자료구조인지 GitHub CPython repo를 보면서 감을 잡았습니다. | ||
[CPython에서 Set Object C언어 코드](https://github.com/python/cpython/blob/main/Objects/setobject.c) | ||
|
||
## 풀이 과정 | ||
|
||
![](https://res.cloudinary.com/gyunseo-blog/image/upload/f_auto/v1716474146/image_zc53hm.png) | ||
|
||
## AC 받은 Python 코드 | ||
|
||
```python | ||
import sys | ||
|
||
input = sys.stdin.readline | ||
|
||
if __name__ == "__main__": | ||
N, M = map(int, input().rstrip().split()) | ||
S = set() | ||
ans = 0 | ||
for _ in range(N): | ||
S.add(input().rstrip()) | ||
for _ in range(M): | ||
if input().rstrip() in S: | ||
ans += 1 | ||
print(ans) | ||
|
||
``` |