๋ ์์ ํฉ
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())
ใด๋ฐํ์ ์๋ฌ
'Coding Test' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
StringTokenizer ์ฌ์ฉํด์ ๋ฌธ์์ด์ ๋จ์ด ๊ฐฏ์ ๊ตฌํ๊ธฐ (0) | 2024.03.08 |
---|---|
์ด์ง ํ์ (Binary Search) ์๊ฐ ๋ณต์ก๋๊ฐ ์ logn์ผ๊น? (0) | 2024.03.08 |
2023.12.02~03 ์ฝ๋ฉํ ์คํธ (1) | 2023.12.03 |