Skip to content

Commit d56b1b4

Browse files
committed
[Silver V] Title: 크로아티아 알파벳, Time: 32 ms, Memory: 32412 KB -BaekjoonHub
1 parent 321e241 commit d56b1b4

2 files changed

Lines changed: 148 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+
메모리: 32412 KB, 시간: 32 ms
8+
9+
### 분류
10+
11+
구현, 문자열
12+
13+
### 제출 일자
14+
15+
2025년 6월 24일 21:18:23
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: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# 2941 크로아티아 알파벳
2+
# 실버 5
3+
4+
import sys
5+
input = sys.stdin.readline
6+
7+
line = input().strip()
8+
9+
cnt = 0
10+
idx = 0
11+
L = len(line)
12+
13+
while idx < L:
14+
# 길이가 3인 'dz='부터 체크
15+
if line.startswith("dz=", idx): # idx번째에서 시작하는 글자가 "dz="이면 True 반환
16+
idx += 3
17+
18+
# 길이가 2
19+
elif line.startswith(("c=", "c-", "d-", "lj", "nj", "s=", "z="), idx):
20+
idx += 2
21+
22+
# 길이가 1 (나머지)
23+
else:
24+
idx += 1
25+
26+
cnt += 1
27+
28+
29+
print(cnt)
30+
31+
32+
"""
33+
# line의 길이가 3 이상이어야 성립하는 코드 -> 인덱스 에러
34+
35+
while True:
36+
if line[idx] == 'c':
37+
if line[idx+1] == '=' or '-':
38+
idx += 1
39+
cnt += 1
40+
elif line[idx] == 'd':
41+
if line[idx+1] == 'z' and line[idx+2] == '=':
42+
idx += 2
43+
elif line[idx+1] == '-':
44+
idx += 1
45+
cnt += 1
46+
elif line[idx] == 'l':
47+
if line[idx+1] == 'j':
48+
idx += 1
49+
cnt += 1
50+
elif line[idx] == 'n':
51+
if line[idx+1] == 'j':
52+
idx += 1
53+
cnt += 1
54+
elif line[idx] == 's':
55+
if line[idx+1] == '=':
56+
idx += 1
57+
cnt += 1
58+
elif line[idx] == 'z':
59+
if line[idx+1] == '=':
60+
idx += 1
61+
cnt += 1
62+
else:
63+
cnt += 1
64+
idx += 1
65+
66+
if idx >= len(line):
67+
break
68+
69+
print(cnt)
70+
71+
"""

0 commit comments

Comments
 (0)