BOJ/Swift

백준 1000번 A+B swift

띵지니어 2023. 6. 22. 14:06

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

 

1000번: A+B

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

www.acmicpc.net

 

내 코드

let input = readLine()!.split(separator: " ")
print(Int(input[0])! + Int(input[1])!)

Review

 

readline() 은 리턴값이 옵셔널 이에요!


따라서 Swift에서 input을 받을 때
 옵셔널 언래핑 과정 생각해 줘야 해요.


이상으로 swift 언어의 가장 기본적인 문제를 풀어 보았습니다.

관련 내용은 옵셔널 관련 글에서도 찾아볼 수 있어요!

 

https://thingjin.tistory.com/entry/Swift-Optional-%EA%B0%9C%EB%85%90-%EC%95%8C%EC%95%84-%EB%B3%B4%EA%B8%B0-nil-%EC%A0%95%EC%9D%98

 

[Swift] Optional 개념 알아 보기, nil 정의

Optional Swift를 조금이라도 접해본 분들은 많이 들어봤을 옵셔널!! 에 대해서 알아 보기로 해요!!! 정의 : 래핑 된 값(Wrapped) 또는 값의 부재(absence)를 나타내는 타입이에요~ 애플은 정의를 너무 어렵

thingjin.tistory.com

https://thingjin.tistory.com/entry/Swift-Optional-Unwrapping-1-%EA%B0%95%EC%A0%9C-%EC%B6%94%EC%B6%9C-Forced-Unwrapping

 

[Swift] Optional Unwrapping (1) - 강제 추출 (Forced Unwrapping)

https://thingjin.tistory.com/entry/Swift-Optional-%EA%B0%9C%EB%85%90-%EC%95%8C%EC%95%84-%EB%B3%B4%EA%B8%B0-nil-%EC%A0%95%EC%9D%98 [Swift] Optional 개념 알아 보기, nil 정의Optional Swift를 조금이라도 접해본 분들은 많이 들어봤을 옵

thingjin.tistory.com

 

'BOJ > Swift' 카테고리의 다른 글

백준 17939번 Gazzzua 파이썬  (0) 2024.06.03
백준 2579번 계단 오르기 Swift  (0) 2024.05.13
백준 2609번 최대공약수와 최소공배수 Swift  (0) 2024.04.18
백준 2407번 조합 Swift  (0) 2024.04.17