분류 전체보기
-
import Foundation func solution(_ id_list:[String], _ report:[String], _ k:Int) -> [Int] { var reported: [String: Int] = [:] var user: [String: [String]] = [:] for r in Set(report) { let splited = r.split(separator: " ").map { String($0) } user[splited[0]] = (user[splited[0]] ?? []) + [splited[1]] reported[splited[1]] = (reported[splited[1]] ?? 0) + 1 } return id_list.map { id in return (user[id..
[Swift] 신고 결과 받기import Foundation func solution(_ id_list:[String], _ report:[String], _ k:Int) -> [Int] { var reported: [String: Int] = [:] var user: [String: [String]] = [:] for r in Set(report) { let splited = r.split(separator: " ").map { String($0) } user[splited[0]] = (user[splited[0]] ?? []) + [splited[1]] reported[splited[1]] = (reported[splited[1]] ?? 0) + 1 } return id_list.map { id in return (user[id..
2023.02.15 -
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() }
[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() }
2023.02.15 -
import Foundation func solution(_ X:String, _ Y:String) -> String { var result = [String]() for i in 0...9 { result += Array(repeating: String(i), count: min(X.filter{String($0) == String(i)}.count, Y.filter {String($0) == String(i)}.count)) } return result.isEmpty ? "-1" : result.filter{$0 == "0"}.count == result.count ? "0" : result.sorted(by: >).joined() }
[Swift] 숫자 짝궁import Foundation func solution(_ X:String, _ Y:String) -> String { var result = [String]() for i in 0...9 { result += Array(repeating: String(i), count: min(X.filter{String($0) == String(i)}.count, Y.filter {String($0) == String(i)}.count)) } return result.isEmpty ? "-1" : result.filter{$0 == "0"}.count == result.count ? "0" : result.sorted(by: >).joined() }
2023.02.15 -
import Foundation func solution(_ s:String) -> Int { let answer = s.replacingOccurrences(of: "zero", with: "0") .replacingOccurrences(of: "one", with: "1") .replacingOccurrences(of: "two", with: "2") .replacingOccurrences(of: "three", with: "3") .replacingOccurrences(of: "four", with: "4") .replacingOccurrences(of: "five", with: "5") .replacingOccurrences(of: "six", with: "6") .replacingOccurren..
[Swift] 숫자 문자열과 영단어import Foundation func solution(_ s:String) -> Int { let answer = s.replacingOccurrences(of: "zero", with: "0") .replacingOccurrences(of: "one", with: "1") .replacingOccurrences(of: "two", with: "2") .replacingOccurrences(of: "three", with: "3") .replacingOccurrences(of: "four", with: "4") .replacingOccurrences(of: "five", with: "5") .replacingOccurrences(of: "six", with: "6") .replacingOccurren..
2023.02.15 -
import Foundation func solution(_ n:Int) -> String { return "\(String(repeating: "수박", count: n/2))\(n % 2 == 0 ? "" : "수")" }
[Swift] 수박수박수박수박수박수?import Foundation func solution(_ n:Int) -> String { return "\(String(repeating: "수박", count: n/2))\(n % 2 == 0 ? "" : "수")" }
2023.02.14 -
import Foundation func isPrime(_ n: Int) -> Bool { if (n Int { return (2...n).filter { isPrime($0) }.count }
[Swift] 소수 찾기import Foundation func isPrime(_ n: Int) -> Bool { if (n Int { return (2...n).filter { isPrime($0) }.count }
2023.02.14 -
import Foundation func isPrime(num :Int) -> Bool { if num Int { var result = 0 let num = nums.sorted() for i in stride(from: 0, through: num.count-3, by: 1){ for j in stride(from: i+1, through: num.count-2, by: 1){ for k in stride(from: j+1, through..
[Swift] 소수 만들기import Foundation func isPrime(num :Int) -> Bool { if num Int { var result = 0 let num = nums.sorted() for i in stride(from: 0, through: num.count-3, by: 1){ for j in stride(from: i+1, through: num.count-2, by: 1){ for k in stride(from: j+1, through..
2023.02.14 -
import Foundation func solution(_ survey:[String], _ choices:[Int]) -> String { let type = [["R", "T"], ["C", "F"], ["J", "M"], ["A", "N"]] let score = [3,2,1,0,1,2,3] var mbti: [String: Int] = ["R" : 0, "T" : 0, "C" : 0, "F" : 0, "J" : 0, "M" : 0, "A" : 0, "N" : 0] zip(survey, choices).forEach { let first = String($0.first!) let last = String($0.last!) if $1 < 4 { mbti[first]! += score[$1 - 1] ..
[Swift] 성격 유형 검사하기import Foundation func solution(_ survey:[String], _ choices:[Int]) -> String { let type = [["R", "T"], ["C", "F"], ["J", "M"], ["A", "N"]] let score = [3,2,1,0,1,2,3] var mbti: [String: Int] = ["R" : 0, "T" : 0, "C" : 0, "F" : 0, "J" : 0, "M" : 0, "A" : 0, "N" : 0] zip(survey, choices).forEach { let first = String($0.first!) let last = String($0.last!) if $1 < 4 { mbti[first]! += score[$1 - 1] ..
2023.02.14