Skip to content

Commit 433cf6d

Browse files
committed
[Silver V] Title: 크로아티아 알파벳, Time: 8 ms, Memory: 69100 KB -BaekjoonHub
1 parent baf0c99 commit 433cf6d

2 files changed

Lines changed: 100 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# [Silver V] 크로아티아 알파벳 - 2941
2+
3+
[문제 링크](https://www.acmicpc.net/problem/2941)
4+
5+
### 성능 요약
6+
7+
메모리: 69100 KB, 시간: 8 ms
8+
9+
### 분류
10+
11+
구현, 문자열
12+
13+
### 제출 일자
14+
15+
2025년 1월 27일 22:42:33
16+
17+
### 문제 설명
18+
19+
<p>예전에는 운영체제에서 크로아티아 알파벳을 입력할 수가 없었다. 따라서, 다음과 같이 크로아티아 알파벳을 변경해서 입력했다.</p>
20+
21+
<table class="table table-bordered table-center-20 th-center td-center">
22+
<thead>
23+
<tr>
24+
<th>크로아티아 알파벳</th>
25+
<th>변경</th>
26+
</tr>
27+
</thead>
28+
<tbody>
29+
<tr>
30+
<td>č</td>
31+
<td>c=</td>
32+
</tr>
33+
<tr>
34+
<td>ć</td>
35+
<td>c-</td>
36+
</tr>
37+
<tr>
38+
<td>dž</td>
39+
<td>dz=</td>
40+
</tr>
41+
<tr>
42+
<td>đ</td>
43+
<td>d-</td>
44+
</tr>
45+
<tr>
46+
<td>lj</td>
47+
<td>lj</td>
48+
</tr>
49+
<tr>
50+
<td>nj</td>
51+
<td>nj</td>
52+
</tr>
53+
<tr>
54+
<td>š</td>
55+
<td>s=</td>
56+
</tr>
57+
<tr>
58+
<td>ž</td>
59+
<td>z=</td>
60+
</tr>
61+
</tbody>
62+
</table>
63+
64+
<p>예를 들어, ljes=njak은 크로아티아 알파벳 6개(lj, e, š, nj, a, k)로 이루어져 있다. 단어가 주어졌을 때, 몇 개의 크로아티아 알파벳으로 이루어져 있는지 출력한다.</p>
65+
66+
<p>dž는 무조건 하나의 알파벳으로 쓰이고, d와 ž가 분리된 것으로 보지 않는다. lj와 nj도 마찬가지이다. 위 목록에 없는 알파벳은 한 글자씩 센다.</p>
67+
68+
### 입력
69+
70+
<p>첫째 줄에 최대 100글자의 단어가 주어진다. 알파벳 소문자와 '-', '='로만 이루어져 있다.</p>
71+
72+
<p>단어는 크로아티아 알파벳으로 이루어져 있다. 문제 설명의 표에 나와있는 알파벳은 변경된 형태로 입력된다.</p>
73+
74+
### 출력
75+
76+
<p>입력으로 주어진 단어가 몇 개의 크로아티아 알파벳으로 이루어져 있는지 출력한다.</p>
77+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
let croatiaWord = readLine()!.map { String($0) }
2+
let croatiaAlphabetTwo = ["c=", "c-", "d-", "lj", "nj", "s=", "z="]
3+
let croatiaAlphabetThree = ["dz="]
4+
var answer = 0
5+
var passCount = 0
6+
for i in croatiaWord.indices {
7+
if passCount > 0 {
8+
passCount -= 1
9+
continue
10+
}
11+
if croatiaAlphabetTwo.contains(croatiaWord.suffix(croatiaWord.count - i).prefix(2).joined()) {
12+
answer += 1
13+
passCount += 1
14+
continue
15+
}
16+
if croatiaAlphabetThree.contains(croatiaWord.suffix(croatiaWord.count - i).prefix(3).joined()) {
17+
answer += 1
18+
passCount += 2
19+
continue
20+
}
21+
answer += 1
22+
}
23+
print(answer)

0 commit comments

Comments
 (0)