반응형
문제
https://www.acmicpc.net/problem/1000
1000번: A+B
두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.
www.acmicpc.net
풀이
- 입력이 필요한 문제
- Swift에서는 readLine() 으로 입력을 받을 수 있음
- 입력을 받고 split(seperator:) 메서드로 분리해서 Int 자료형으로 변환
- 더한 값을 출력
소스코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let input = readLine()!.split(separator: " ").map { Int($0)! } | |
let a = input[0], b = input[1] | |
print(a + b) |
후기
- 맨 처음 풀었을 때는 입력을 어떻게 받아와야할 지 몰랐어서 검색을 했었던 것 같음..
반응형
'PS > 백준' 카테고리의 다른 글
[BOJ] 백준 10998 AxB (Swift) (0) | 2022.11.27 |
---|---|
[BOJ] 백준 1001 A-B (Swift) (0) | 2022.11.27 |
[BOJ] 백준 2557 Hello World (Swift) (0) | 2022.11.27 |
[BOJ] 백준 2036 수열의 점수 (Swift) (0) | 2022.11.19 |
[BOJ] 백준 5545 최고의 피자 (Swift) (0) | 2022.11.13 |