반응형
문제
https://www.acmicpc.net/problem/3003
3003번: 킹, 퀸, 룩, 비숍, 나이트, 폰
첫째 줄에 동혁이가 찾은 흰색 킹, 퀸, 룩, 비숍, 나이트, 폰의 개수가 주어진다. 이 값은 0보다 크거나 같고 10보다 작거나 같은 정수이다.
www.acmicpc.net
풀이
- "-" 연산만 안다면 쉽게 풀 수 있는 문제..?
- for문을 사용하면 코드의 양을 줄일 수 있겠다고 느꼈음
소스코드
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 piece = [1, 1, 2, 2, 2, 8] | |
let input = readLine()!.split(separator: " ").map { Int($0)! } | |
piece.enumerated().forEach { index, piece in | |
print(piece - input[index], terminator: " ") | |
} | |
// 이렇게도 가능 | |
// print( | |
// piece[0] - input[0], piece[1] - input[1], piece[2] - input[2], | |
// piece[3] - input[3], piece[4] - input[4], piece[5] - input[5] | |
// ) |
후기
- "-" 연산만 사용해서 쉽게 풀 수 있었음
- for문을 몰라도 풀 수 있는 문제..! 안다면 코드의 양을 줄일 수 있고, 더 가독성이 좋다고 느낌!
반응형
'PS > 백준' 카테고리의 다른 글
[BOJ] 백준 2588 곱셈 (Swift) (0) | 2022.11.30 |
---|---|
[BOJ] 백준 10430 나머지 (Swift) (0) | 2022.11.29 |
[BOJ] 백준 18108 1998년생인 내가 태국에서는 2541년생?! (Swift) (0) | 2022.11.27 |
[BOJ] 백준 10926 ??! (Swift) (0) | 2022.11.27 |
[BOJ] 백준 10869 사칙연산 (Swift) (0) | 2022.11.27 |