ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90

๐Ÿšฉ ์ž๋ฃŒ๊ตฌ์กฐ, ๋ฌธ์ž์—ด, ์ •๋ ฌ

 

thinking

์ค‘๋ณต์—†์ด ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ๋“ฃ๋„ ๋ชปํ•œ ์‚ฌ๋žŒ๊ณผ ๋ณด๋„ ๋ชปํ•œ ์‚ฌ๋žŒ์„ ๊ฐ๊ฐ set์— ๋„ฃ์€ ํ›„, ๊ต์ง‘ํ•ฉ์„ ๊ตฌํ•ด ์ •๋ ฌํ–ˆ๋‹ค.

ํŒŒ์ด์ฌ set์˜ ํŠน์ง• ๋•๋ถ„์— ์‰ฝ๊ฒŒ ํ•ด๊ฒฐํ–ˆ๋‹ค.

 

์ฝ”๋“œ

N, M = map(int, input().split())

set_N = set()  # ๋“ฃ๋„ ๋ชปํ•œ ์‚ฌ๋žŒ์˜ ๋ช…๋‹จ์„ ๋‹ด์„ set
set_M = set()  # ๋ณด๋„ ๋ชปํ•œ ์‚ฌ๋žŒ์˜ ๋ช…๋‹จ์„ ๋‹ด์„ set
for _ in range(N):
    set_N.add(input())
for _ in range(M):
    set_M.add(input())

res = sorted(list(set_N & set_M))  # ๊ต์ง‘ํ•ฉ์„ ๊ตฌํ•œ๋‹ค์Œ ์ •๋ ฌ

print(len(res))
for ele in res:
    print(ele)

 

ํ•œ์ค„ํ‰

์ฑ„์ ํ•˜๋Š”๋ฐ ์ฒด๊ฐ์ƒ 293872387274์‹œ๊ฐ„ ๊ฑธ๋ฆฐ๊ฑฐ ๊ฐ™๋‹ค. ํŒŒ์ด์ฌ ๋„ˆ๋ฌด ๋Š๋ฆฌ๋‹ค..

๋Œ“๊ธ€