import Foundation
func solution(_ new_id:String) -> String {
var result = new_id.lowercased().components(separatedBy: ["~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "=", "+", "[", "]", "{", "}", ":", "?", ",", "<", ">", "/"]).joined().components(separatedBy: ".").filter { $0 != ""
}.joined(separator: ".").trimmingCharacters(in: ["."])
if result.isEmpty {
result = "a"
}
if 15 <= result.count {
result = "\(result.prefix(15))"
}
result = result.trimmingCharacters(in: ["."])
if result.count <= 2 {
result += String.init(repeating: "\(result.last!)", count: 3-result.count)
}
return result
}
'프로그래머스 > 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.15 |