카테고리 없음

[백준 10950][Swift] 두 정수 A와 B를 입력받은 다음, A+B를 출력 -3

moving 2022. 3. 31. 14:39
728x90

 

 

코드

let inputT = Int(readLine()!)!

for _ in 1...inputT {
    let inputNum = readLine()?.split(separator: " ")
    let a = Int(inputNum?.first ?? "0")!
    let b = Int(inputNum?.last ?? "0")!
    print(a + b)
}

혹은

map 메소드 이용

let inputT = Int(readLine()!)!

for _ in 1...inputT {
    let inputNum = (readLine()?.split(separator: " ").map { Int($0)! })!
    print(inputNum[0] + inputNum[1])
}

 

 

https://www.acmicpc.net/problem/10950

 

10950번: A+B - 3

두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.

www.acmicpc.net