๐Ÿ”ฃ[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๋ชจ์Šค๋ถ€ํ˜ธ (1)

Chobbyยท2022๋…„ 10์›” 13์ผ
1

Programmers

๋ชฉ๋ก ๋ณด๊ธฐ
96/349

๐Ÿงก๋ฌธ์ œ ์„ค๋ช…

๋จธ์“ฑ์ด๋Š” ์นœ๊ตฌ์—๊ฒŒ ๋ชจ์Šค๋ถ€ํ˜ธ๋ฅผ ์ด์šฉํ•œ ํŽธ์ง€๋ฅผ ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค. ๊ทธ๋ƒฅ์€ ์ฝ์„ ์ˆ˜ ์—†์–ด ์ด๋ฅผ ํ•ด๋…ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด letter๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, letter๋ฅผ ์˜์–ด ์†Œ๋ฌธ์ž๋กœ ๋ฐ”๊พผ ๋ฌธ์ž์—ด์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”.
๋ชจ์Šค๋ถ€ํ˜ธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

morse = {
'.-':'a',
'-...':'b',
'-.-.':'c',
'-..':'d',
'.':'e',
'..-.':'f',
'--.':'g',
'....':'h',
'..':'i',
'.---':'j',
'-.-':'k',
'.-..':'l',
'--':'m',
'-.':'n',
'---':'o',
'.--.':'p',
'--.-':'q',
'.-.':'r',
'...':'s',
'-':'t',
'..-':'u',
'...-':'v',
'.--':'w',
'-..-':'x',
'-.--':'y',
'--..':'z'
}


๐Ÿ’›์ œํ•œ์‚ฌํ•ญ

  • 1 โ‰ค letter์˜ ๊ธธ์ด โ‰ค 1,000
  • return๊ฐ’์€ ์†Œ๋ฌธ์ž์ž…๋‹ˆ๋‹ค.
  • letter์˜ ๋ชจ์Šค๋ถ€ํ˜ธ๋Š” ๊ณต๋ฐฑ์œผ๋กœ ๋‚˜๋ˆ„์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.
  • letter์— ๊ณต๋ฐฑ์€ ์—ฐ์†์œผ๋กœ ๋‘ ๊ฐœ ์ด์ƒ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  • ํ•ด๋…ํ•  ์ˆ˜ ์—†๋Š” ํŽธ์ง€๋Š” ์ฃผ์–ด์ง€์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  • ํŽธ์ง€์˜ ์‹œ์ž‘๊ณผ ๋์—๋Š” ๊ณต๋ฐฑ์ด ์—†์Šต๋‹ˆ๋‹ค.

๐Ÿ’š์ž…์ถœ๋ ฅ ์˜ˆ

letterresult
".... . .-.. .-.. ---""hello"
".--. -.-- - .... --- -.""python"

๐Ÿ’™์ž…์ถœ๋ ฅ ์˜ˆ ์„ค๋ช…

์ž…์ถœ๋ ฅ ์˜ˆ #1

  • .... = h
  • . = e
  • .-.. = l
  • .-.. = l
  • --- = o

๋”ฐ๋ผ์„œ "hello"๋ฅผ return ํ•ฉ๋‹ˆ๋‹ค.

์ž…์ถœ๋ ฅ ์˜ˆ #2

  • .--. = p
  • -.-- = y
    • = t
  • .... = h
  • --- = o
  • -. = n

๋”ฐ๋ผ์„œ "python"์„ return ํ•ฉ๋‹ˆ๋‹ค.


  • a ~ z์— ํ•ด๋‹นํ•˜๋Š” ๋ชจ์Šค๋ถ€ํ˜ธ๊ฐ€ ์ˆœ์„œ๋Œ€๋กœ ๋‹ด๊ธด ๋ฐฐ์—ด์ž…๋‹ˆ๋‹ค.
  • {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."}

๐Ÿ’œ๋‚˜์˜ ํ’€์ด

function solution(letter) {
    const morse = { 
        '.-':'a',
        '-...':'b',
        '-.-.':'c',
        '-..':'d',
        '.':'e',
        '..-.':'f',
        '--.':'g',
        '....':'h',
        '..':'i',
        '.---':'j',
        '-.-':'k',
        '.-..':'l',
        '--':'m',
        '-.':'n',
        '---':'o',
        '.--.':'p',
        '--.-':'q',
        '.-.':'r',
        '...':'s',
        '-':'t',
        '..-':'u',
        '...-':'v',
        '.--':'w',
        '-..-':'x',
        '-.--':'y',
        '--..':'z'
    }
    // ๋ชจ์Šค ๋ถ€ํ˜ธ๋Š” ๊ณต๋ฐฑ์œผ๋กœ ๋‚˜๋‰˜์–ด์ ธ์žˆ์œผ๋ฏ€๋กœ, ๊ณต๋ฐฑ์„ ๊ธฐ์ค€์œผ๋กœ ๋‚˜๋ˆˆ ํ›„ ๊ฐ ๋ชจ์Šค๋ถ€ํ˜ธ๋ฅผ ์ž…๋ ฅ
    return letter.split(" ").map(a => morse[a]).join("")
}
profile
๋‚ด ์ง€์‹์„ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋Š” ๋Œ€๋‹ดํ•จ

0๊ฐœ์˜ ๋Œ“๊ธ€