반응형
문제
https://www.acmicpc.net/problem/10869
10869번: 사칙연산
두 자연수 A와 B가 주어진다. 이때, A+B, A-B, A*B, A/B(몫), A%B(나머지)를 출력하는 프로그램을 작성하시오.
www.acmicpc.net
풀이
- 나머지를 구해야한다면, Double 자료형으로 나누었을 것 같은데 그렇지 않아서 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) | |
print(a - b) | |
print(a * b) | |
print(a / b) | |
print(a % b) |
후기
- 기본연산자를 사용할 수 있으면 아주 쉽게 풀이할 수 있는 문제인 것 같다.
반응형
'PS > 백준' 카테고리의 다른 글
[BOJ] 백준 18108 1998년생인 내가 태국에서는 2541년생?! (Swift) (0) | 2022.11.27 |
---|---|
[BOJ] 백준 10926 ??! (Swift) (0) | 2022.11.27 |
[BOJ] 백준 1008 A/B (Swift) (0) | 2022.11.27 |
[BOJ] 백준 10998 AxB (Swift) (0) | 2022.11.27 |
[BOJ] 백준 1001 A-B (Swift) (0) | 2022.11.27 |