Skip to content

Commit a9a847c

Browse files
committed
[BOJ] 단축키 지정 / 실버 1 / 60분
https://www.acmicpc.net/problem/1283
1 parent bf3774b commit a9a847c

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'''
2+
3+
1.하나의 옵션에 대해 왼쪽에서부터 오른쪽 순서로 단어의 첫 글자가(공백으로 구분하는 것을 이용) 이미 단축키로 지정되었는지 살펴본다.
4+
만약 단축키로 아직 지정이 안 되어있다면 그 알파벳을 단축키로 지정한다.
5+
6+
2. 만약 모든 단어의 첫 글자가 이미 지정이 되어있다면 왼쪽에서부터 차례대로 알파벳을 보면서 단축키로 지정 안 된 것이 있다면 단축키로 지정한다.
7+
8+
3.어떠한 것도 단축키로 지정할 수 없다면 그냥 놔두며 대소문자를 구분치 않는다.
9+
10+
4. 위의 규칙을 첫 번째 옵션부터 N번째 옵션까지 차례대로 적용한다.
11+
12+
'''
13+
14+
import sys
15+
16+
inp = sys.stdin.readline
17+
18+
N = int(inp())
19+
20+
# 단축키로 지정된 대문자 알파벳들
21+
used_shortcuts = set()
22+
23+
# 결과 저장용 리스트
24+
results = []
25+
26+
for _ in range(N):
27+
original = inp().strip()
28+
shortcut_index = -1
29+
words = original.split()
30+
index_in_string = 0
31+
32+
# 1단계: 각 단어의 첫 글자 확인
33+
for word in words:
34+
char = word[0].upper()
35+
if char not in used_shortcuts:
36+
used_shortcuts.add(char)
37+
shortcut_index = index_in_string
38+
break
39+
index_in_string += len(word) + 1 # 공백 포함해서 다음 인덱스 계산
40+
41+
# 2단계: 전체 문자열 순회
42+
if shortcut_index == -1:
43+
for i, char in enumerate(original):
44+
if char != ' ' and char.upper() not in used_shortcuts:
45+
used_shortcuts.add(char.upper())
46+
shortcut_index = i
47+
break
48+
49+
# 단축키 표시
50+
if shortcut_index != -1:
51+
marked = (
52+
original[:shortcut_index]
53+
+ '[' + original[shortcut_index] + ']'
54+
+ original[shortcut_index + 1:]
55+
)
56+
results.append(marked)
57+
else:
58+
results.append(original)
59+
60+
# 출력
61+
print('\n'.join(results))

0 commit comments

Comments
 (0)