1 ๋ถ„ ์†Œ์š”

๋ฐฑ์ค€ ์‚ฌ์ดํŠธ ๋งํฌ

๋ฌธ์ œ

์ •๋ ฌ๋˜์–ด์žˆ๋Š” ๋‘ ๋ฐฐ์—ด A์™€ B๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋‘ ๋ฐฐ์—ด์„ ํ•ฉ์นœ ๋‹ค์Œ ์ •๋ ฌํ•ด์„œ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— ๋ฐฐ์—ด A์˜ ํฌ๊ธฐ N, ๋ฐฐ์—ด B์˜ ํฌ๊ธฐ M์ด ์ฃผ์–ด์ง„๋‹ค. (1 โ‰ค N, M โ‰ค 1,000,000)

๋‘˜์งธ ์ค„์—๋Š” ๋ฐฐ์—ด A์˜ ๋‚ด์šฉ์ด, ์…‹์งธ ์ค„์—๋Š” ๋ฐฐ์—ด B์˜ ๋‚ด์šฉ์ด ์ฃผ์–ด์ง„๋‹ค. ๋ฐฐ์—ด์— ๋“ค์–ด์žˆ๋Š” ์ˆ˜๋Š” ์ ˆ๋Œ“๊ฐ’์ด 109๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ •์ˆ˜์ด๋‹ค.

์ถœ๋ ฅ

์ฒซ์งธ ์ค„์— ๋‘ ๋ฐฐ์—ด์„ ํ•ฉ์นœ ํ›„ ์ •๋ ฌํ•œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

์˜ˆ์ œ ์ž…๋ ฅ 1

2 2
3 5
2 9

์˜ˆ์ œ ์ถœ๋ ฅ 1

2 3 5 9

์˜ˆ์ œ ์ž…๋ ฅ 2

2 1
4 7
1

์˜ˆ์ œ ์ถœ๋ ฅ 2

1 4 7

์˜ˆ์ œ ์ž…๋ ฅ 3

4 3
2 3 5 9
1 4 7

์˜ˆ์ œ ์ถœ๋ ฅ 3

1 2 3 4 5 7 9

๋ฌธ์ œ๋ฅผ ํ’€๋ฉด์„œ ๋ง‰ํ˜”๋˜ ๋ถ€๋ถ„

  • ๋‘ ๋ฐฐ์—ด์„ ํ•ฉ์ณ์„œ ์ •๋ ฌํ•ด์ฃผ๋Š” ๊ฐ„๋‹จํ•œ ๋ฌธ์ œ์ด๋‹ค.
  1. join ํ•จ์ˆ˜

join ํ•จ์ˆ˜๋Š” ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋“ค์–ด์˜จ ๋ฆฌ์ŠคํŠธ์— ์žˆ๋Š” ์š”์†Œ ํ•˜๋‚˜ํ•˜๋‚˜๋ฅผ ํ•ฉ์ณ์„œ ํ•˜๋‚˜์˜ ๋ฌธ์ž์—ด๋กœ ๋ฐ”๊พธ์–ด ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜์ด๋‹ค.

a = ['a', 'b', 'c', 'd']
print(a)

# join ์ด์šฉ
result1 = " ".join(a)
print(result1)
['a', 'b', 'c', 'd']
a b c d
  1. unpacking (*list) ์‚ฌ์šฉ

์ธ์ˆ˜๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ๋„ฃ์„ ๋•Œ ๋ฆฌ์ŠคํŠธ๋‚˜ ํŠœํ”Œ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ๋ฆฌ์ŠคํŠธ์™€ ํŠœํ”Œ ์•ž์— *์„ ๋ถ™์—ฌ ์ธ์ž๋“ค์„ ์ผ์ผํžˆ ๋„˜๊ธฐ๋Š” ํšจ๊ณผ์™€ ๊ฐ™์€ ํšจ๊ณผ๋ฅผ ์ค€๋‹ค.

a = ['a', 'b', 'c', 'd']
print(*a)
a b c d

์ฝ”๋“œ

ver(1) - join ์‚ฌ์šฉ
import sys

a, b = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
list = A + B
answer = ' '.join(map(str, sorted(list)))
print(answer)
ver(2) - (*list) ์‚ฌ์šฉ
n, m = list(map(int,input().split()))
n_list = list(map(int,input().split()))
m_list = list(map(int,input().split()))

l = n_list+m_list
l.sort(reverse=False)
print(*l)

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ