시저 암호
https://school.programmers.co.kr/learn/courses/30/lessons/12926
function solution(s, n) {
// a - z: 97~122
// A - Z: 65~90
var answer = [];
s = s.split('');
s.forEach((d) => {
let code = d.charCodeAt();
if(d === ' ') { answer.push(' '); }
else if(code+n > 122 && code >= 97) {
answer.push(String.fromCharCode(97+(code+n - 122-1)));
}
else if(code+n > 90 && code <= 90) {
answer.push(String.fromCharCode(65+(code+n - 90-1)));
}
else {
answer.push(String.fromCharCode(code+n));
}
})
return answer.join("");
}
728x90
'Algorithm&CodingTest > Programmers' 카테고리의 다른 글
[Programmers] 2021 카카오 채용연계형 인턴십 - 숫자 문자열과 영단어 (0) | 2023.01.31 |
---|---|
[Programmers] 코딩테스트 입문 - 소인수분해 (0) | 2023.01.31 |
[Programmers] 연습문제 - 콜라츠 추측 (0) | 2023.01.31 |
[Programmers] 연습문제 - 핸드폰 번호 가리기 (0) | 2023.01.31 |
[ Programmers ] 연습문제 - lv1 - 제일 작은 수 제거하기 (0) | 2022.11.20 |