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 |