https://www.acmicpc.net/problem/1181
ํ์ด
1๋ฒ ํ์ด
# ๋ฐฑ์ค 1181๋ฒ ๋ฌธ์ - ๋จ์ด ์ ๋ ฌ
# 1. ๊ธธ์ด๊ฐ ์งง์ ๊ฒ๋ถํฐ
# 2. ๊ธธ์ด๊ฐ ๊ฐ์ผ๋ฉด ์ฌ์ ์์ผ๋ก
import sys
n = int(sys.stdin.readline().strip())
words = []
for _ in range(n):
words.append(sys.stdin.readline().strip())
words = list(set(words)) # ์ค๋ณต ์ ๊ฑฐ
words.sort(key = lambda x: (len(x), x)) # ์ฒซ๋ฒ์งธ๋ก len(x) ์กฐ๊ฑด ์ํ ํ x ์์ผ๋ก ์ ๋ ฌ
for i in words:
print(i)
2๋ฒ ํ์ด
# ๋ฐฑ์ค 1181๋ฒ ๋ฌธ์ - ๋จ์ด ์ ๋ ฌ
# 1. ๊ธธ์ด๊ฐ ์งง์ ๊ฒ๋ถํฐ
# 2. ๊ธธ์ด๊ฐ ๊ฐ์ผ๋ฉด ์ฌ์ ์์ผ๋ก
import sys
n = int(sys.stdin.readline().strip())
words = []
for _ in range(n):
words.append(sys.stdin.readline().strip())
new_words = set(words) # ์ค๋ณต ์ ๊ฑฐ
words = list(new_words)
words.sort() # ์ฌ์ ์์ผ๋ก ์ ๋ ฌ
words.sort(key=len)
for i in words:
print(i)
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] [Python] 11650๋ฒ_์ขํ ์ ๋ ฌํ๊ธฐ (0) | 2022.02.26 |
---|---|
[๋ฐฑ์ค] (Python) 11718๋ฒ_๊ทธ๋๋ก ์ถ๋ ฅํ๊ธฐ (0) | 2022.02.24 |
[๋ฐฑ์ค] (Python) 1427๋ฒ_์์ฝ๋ฉ (0) | 2022.02.24 |
[๋ฐฑ์ค] (Python) 10989๋ฒ_์ ์ ๋ ฌํ๊ธฐ 3 (0) | 2022.02.21 |
[๋ฐฑ์ค] (Python) 10610๋ฒ_30 (0) | 2022.02.20 |