We will find a way, we always have.

-interstellar

Problem Solving/๋ฐฑ์ค€

[๋ฐฑ์ค€] 14425๋ฒˆ: ๋ฌธ์ž์—ด ์ง‘ํ•ฉ - ํŒŒ์ด์ฌ

Redddy 2022. 5. 15. 23:36

๐Ÿ“• ํ’€์ด

์ œ๋ชฉ์ฒ˜๋Ÿผ ์ง‘ํ•ฉ์„ ์‚ฌ์šฉํ•ด์„œ ํ’€๋ฉด ๋˜๋Š” ๋ฌธ์ œ์ด๋‹ค.
์ฒ˜์Œ์—๋Š” ์ฐจ์ง‘ํ•ฉ์„ ์ด์šฉํ•˜์—ฌ ํ’€์ด ํ•˜์˜€์œผ๋‚˜ ์˜ค๋‹ต์œผ๋กœ ์ฒ˜๋ฆฌ๋˜์—ˆ๊ณ , ๋ฐ”๋กœ ๋– ์˜ค๋ฅธ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์€ ํ•˜๋‚˜ํ•˜๋‚˜ ์ฒดํฌํ•ด์ฃผ๋Š” ๋ฐฉ๋ฒ•์ด์—ˆ๋‹ค.

 

๐Ÿ’ป ์ฝ”๋“œ

import sys
input = sys.stdin.readline

n,m = map(int,input().rstrip().split())
cnt = 0
s = set()
check = set()
for i in range(n):
    s.add(input().rstrip()) # ๊ธฐ์ค€์ด ๋˜๋Š” ์ง‘ํ•ฉ

for j in range(m):
    word = input().rstrip()
    if word in s: # ๊ธฐ์ค€ ์ง‘ํ•ฉ์— ์ƒˆ๋กœ ์ƒˆ๋กœ ์ž…๋ ฅ๋œ ๋ฌธ์ž๊ฐ€ ์žˆ๋‹ค๋ฉด ์นด์šดํŠธ
        cnt += 1
print(cnt)

 

๐Ÿ“Ž ๋ฌธ์ œ ๋งํฌ : ๋ฌธ์ž์—ด ์ง‘ํ•ฉ

 

14425๋ฒˆ: ๋ฌธ์ž์—ด ์ง‘ํ•ฉ

์ฒซ์งธ ์ค„์— ๋ฌธ์ž์—ด์˜ ๊ฐœ์ˆ˜ N๊ณผ M (1 ≤ N ≤ 10,000, 1 ≤ M ≤ 10,000)์ด ์ฃผ์–ด์ง„๋‹ค.  ๋‹ค์Œ N๊ฐœ์˜ ์ค„์—๋Š” ์ง‘ํ•ฉ S์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ๋ฌธ์ž์—ด๋“ค์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹ค์Œ M๊ฐœ์˜ ์ค„์—๋Š” ๊ฒ€์‚ฌํ•ด์•ผ ํ•˜๋Š” ๋ฌธ์ž์—ด๋“ค์ด ์ฃผ์–ด

www.acmicpc.net