새소식

인기 검색어

프로그래머스/Lv.1

[Swift] 시저 암호

  • -
import Foundation

func solution(_ s:String, _ n:Int) -> String {
    return s.utf8.map {
        var asciiCode = Int($0)
        switch asciiCode {
            case 65...90:
                asciiCode = (asciiCode + n - 65) % 26 + 65
            case 97...122:
                asciiCode = (asciiCode + n - 97) % 26 + 97
            default:
                break
        }
        return String(UnicodeScalar(asciiCode)!)
    }.joined()
}

 

'프로그래머스 > Lv.1' 카테고리의 다른 글

[Swift] 신규 아이디 추천  (0) 2023.02.15
[Swift] 신고 결과 받기  (0) 2023.02.15
[Swift] 숫자 짝궁  (0) 2023.02.15
[Swift] 숫자 문자열과 영단어  (0) 2023.02.15
[Swift] 수박수박수박수박수박수?  (0) 2023.02.14
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.