Skip to content

Commit 9e17dbf

Browse files
committed
[level 0] Title: 모스부호 (1), Time: 0.24 ms, Memory: 80.7 MB -BaekjoonHub
1 parent f38a084 commit 9e17dbf

2 files changed

Lines changed: 127 additions & 0 deletions

File tree

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# [level 0] 모스부호 (1) - 120838
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/120838)
4+
5+
### 성능 요약
6+
7+
메모리: 80.7 MB, 시간: 0.24 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 코딩테스트 입문
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2026년 05월 05일 18:01:24
20+
21+
### 문제 설명
22+
23+
<p>머쓱이는 친구에게 모스부호를 이용한 편지를 받았습니다. 그냥은 읽을 수 없어 이를 해독하는 프로그램을 만들려고 합니다. 문자열 <code>letter</code>가 매개변수로 주어질 때, <code>letter</code>를 영어 소문자로 바꾼 문자열을 return 하도록 solution 함수를 완성해보세요.<br>
24+
모스부호는 다음과 같습니다.</p>
25+
<div class="highlight"><pre class="codehilite"><code>morse = {
26+
'.-':'a','-...':'b','-.-.':'c','-..':'d','.':'e','..-.':'f',
27+
'--.':'g','....':'h','..':'i','.---':'j','-.-':'k','.-..':'l',
28+
'--':'m','-.':'n','---':'o','.--.':'p','--.-':'q','.-.':'r',
29+
'...':'s','-':'t','..-':'u','...-':'v','.--':'w','-..-':'x',
30+
'-.--':'y','--..':'z'
31+
}
32+
</code></pre></div>
33+
<hr>
34+
35+
<h5>제한사항</h5>
36+
37+
<ul>
38+
<li>1 ≤ <code>letter</code>의 길이 ≤ 1,000</li>
39+
<li>return값은 소문자입니다.</li>
40+
<li><code>letter</code>의 모스부호는 공백으로 나누어져 있습니다.</li>
41+
<li><code>letter</code>에 공백은 연속으로 두 개 이상 존재하지 않습니다.</li>
42+
<li>해독할 수 없는 편지는 주어지지 않습니다.</li>
43+
<li>편지의 시작과 끝에는 공백이 없습니다.</li>
44+
</ul>
45+
46+
<hr>
47+
48+
<h5>입출력 예</h5>
49+
<table class="table">
50+
<thead><tr>
51+
<th>letter</th>
52+
<th>result</th>
53+
</tr>
54+
</thead>
55+
<tbody><tr>
56+
<td>".... . .-.. .-.. ---"</td>
57+
<td>"hello"</td>
58+
</tr>
59+
<tr>
60+
<td>".--. -.-- - .... --- -."</td>
61+
<td>"python"</td>
62+
</tr>
63+
</tbody>
64+
</table>
65+
<hr>
66+
67+
<h5>입출력 예 설명</h5>
68+
69+
<p>입출력 예 #1</p>
70+
71+
<ul>
72+
<li>.... = h</li>
73+
<li>. = e</li>
74+
<li>.-.. = l</li>
75+
<li>.-.. = l</li>
76+
<li>--- = o</li>
77+
<li>따라서 "hello"를 return 합니다.</li>
78+
</ul>
79+
80+
<p>입출력 예 #2</p>
81+
82+
<ul>
83+
<li>.--. = p</li>
84+
<li>-.-- = y</li>
85+
<li>- = t</li>
86+
<li>.... = h</li>
87+
<li>--- = o</li>
88+
<li>-. = n</li>
89+
<li>따라서 "python"을 return 합니다.</li>
90+
</ul>
91+
92+
<hr>
93+
94+
<ul>
95+
<li>a ~ z에 해당하는 모스부호가 순서대로 담긴 배열입니다.</li>
96+
<li><code>{".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."}</code></li>
97+
</ul>
98+
99+
100+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.HashMap;
2+
import java.util.Map;
3+
4+
class Solution {
5+
public String solution(String letter) {
6+
Map<String, String> morse = new HashMap<>();
7+
morse.put(".-", "a"); morse.put("-...", "b"); morse.put("-.-.", "c");
8+
morse.put("-..", "d"); morse.put(".", "e"); morse.put("..-.", "f");
9+
morse.put("--.", "g"); morse.put("....", "h"); morse.put("..", "i");
10+
morse.put(".---", "j"); morse.put("-.-", "k"); morse.put(".-..", "l");
11+
morse.put("--", "m"); morse.put("-.", "n"); morse.put("---", "o");
12+
morse.put(".--.", "p"); morse.put("--.-", "q"); morse.put(".-.", "r");
13+
morse.put("...", "s"); morse.put("-", "t"); morse.put("..-", "u");
14+
morse.put("...-", "v"); morse.put(".--", "w"); morse.put("-..-", "x");
15+
morse.put("-.--", "y"); morse.put("--..", "z");
16+
17+
StringBuilder answer = new StringBuilder();
18+
19+
String[] morseArray = letter.split(" ");
20+
21+
for (String m : morseArray) {
22+
answer.append(morse.get(m));
23+
}
24+
25+
return answer.toString();
26+
}
27+
}

0 commit comments

Comments
 (0)