Coding Test

2023.12.01 ์ฝ”๋”ฉํ…Œ์ŠคํŠธ

fram 2023. 12. 1. 01:09

๋‘ ์ˆ˜์˜ ํ•ฉ

func solution(_ num1:Int, _ num2:Int) -> Int {
    return num1 + num2
}

 

๋‘ ์ˆ˜์˜ ์ฐจ

func solution(_ num1:Int, _ num2:Int) -> Int {
    return num1 - num2
}

func solution(_ num1: Int, _ num2: Int) -> Int { num1 - num2 }

 

๋‘ ์ˆ˜์˜ ๊ณฑ

func solution(_ num1:Int, _ num2:Int) -> Int { num1 * num2 }

 

๋ชซ ๊ตฌํ•˜๊ธฐ

func solution(_ num1:Int, _ num2:Int) -> Int { num1 / num2 }

 

๋ฌธ์ž์—ด ์ถœ๋ ฅํ•˜๊ธฐ

let s1 = readLine()!
print(s1)
if let str = readLine() { 
    print(str)
}

 

a์™€ b ์ถœ๋ ฅํ•˜๊ธฐ

let n = readLine()!.components(separatedBy: [" "]).map { Int($0)! }
if n.count == 2 {
    print("a = \(n[0])")
    print("b = \(n[1])")
}

 

๋ฌธ์ž์—ด ๋ฐ˜๋ณตํ•ด์„œ ์ถœ๋ ฅํ•˜๊ธฐ

let inp = readLine()!.components(separatedBy: [" "]).map { $0 }
let str = inp[0]
let num = Int(inp[1]) ?? 0
print(String(repeating: str, count: num))

 

๋Œ€์†Œ๋ฌธ์ž ๋ฐ”๊ฟ”์„œ ์ถœ๋ ฅํ•˜๊ธฐ

    let str = Array(readLine()!)
    let result = str.map { value in
        if value.isUppercase {
            return value.lowercased()
        } else {
            return value.uppercased()
        }
    }.joined()
    print(result)

ใ„ดํ†ต๊ณผํ•œ ๋ฐฉ๋ฒ•

    let str = readLine()!.unicodeScalars.map { $0.value }
    let value = str.compactMap { unicode in
        if unicode >= 65, unicode <= 90 {
            return String(UnicodeScalar(unicode + 32)!)
        }
        
        if unicode >= 97, unicode <= 122 {
            return String(UnicodeScalar(unicode - 32)!)
        }
        return nil
    }
    print(value.joined())

ใ„ด๋Ÿฐํƒ€์ž„ ์—๋Ÿฌ 

 

Pexels์—์„œ Julien BRION๋‹˜์˜ ์‚ฌ์ง„: https://www.pexels.com/ko-kr/photo/102061/

๋Œ“๊ธ€์ˆ˜0