File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # [ Silver V] 단어 정렬 - 1181
2+
3+ [ 문제 링크] ( https://www.acmicpc.net/problem/1181 )
4+
5+ ### 성능 요약
6+
7+ 메모리: 72376 KB, 시간: 472 ms
8+
9+ ### 분류
10+
11+ 문자열, 정렬
12+
13+ ### 제출 일자
14+
15+ 2026년 1월 27일 22:30:23
16+
17+ ### 문제 설명
18+
19+ <p >알파벳 소문자로 이루어진 N개의 단어가 들어오면 아래와 같은 조건에 따라 정렬하는 프로그램을 작성하시오.</p >
20+
21+ <ol >
22+ <li>길이가 짧은 것부터</li>
23+ <li>길이가 같으면 사전 순으로</li>
24+ </ol >
25+
26+ <p >단, 중복된 단어는 하나만 남기고 제거해야 한다.</p >
27+
28+ ### 입력
29+
30+ <p >첫째 줄에 단어의 개수 N이 주어진다. (1 ≤ N ≤ 20,000) 둘째 줄부터 N개의 줄에 걸쳐 알파벳 소문자로 이루어진 단어가 한 줄에 하나씩 주어진다. 주어지는 문자열의 길이는 50을 넘지 않는다.</p >
31+
32+ ### 출력
33+
34+ <p >조건에 따라 정렬하여 단어들을 출력한다.</p >
35+
Original file line number Diff line number Diff line change 1+ let N = Int ( readLine ( ) !) !
2+ var wordArray = Array ( repeating: " " , count: N)
3+
4+ for i in 0 ..< N {
5+ wordArray [ i] = readLine ( ) !
6+ }
7+ wordArray = Array ( Set ( wordArray) )
8+
9+ wordArray. sort { a, b in
10+ if a. count != b. count {
11+ return a. count < b. count
12+ } else {
13+ return a < b
14+ }
15+ }
16+
17+ for word in wordArray {
18+ print ( word)
19+ }
You can’t perform that action at this time.
0 commit comments