MUKER_DEV with iOS

[swift] ๋ฐฑ์ค€ - 10812๋ฒˆ: ๋ฐ”๊ตฌ๋‹ˆ ์ˆœ์„œ ๋ฐ”๊พธ๊ธฐ ๋ณธ๋ฌธ

๐Ÿค– ์•Œ๊ณ ๋ฆฌ์ฆ˜/BAEKJOON

[swift] ๋ฐฑ์ค€ - 10812๋ฒˆ: ๋ฐ”๊ตฌ๋‹ˆ ์ˆœ์„œ ๋ฐ”๊พธ๊ธฐ

MUKER 2023. 4. 17. 23:07
 

10812๋ฒˆ: ๋ฐ”๊ตฌ๋‹ˆ ์ˆœ์„œ ๋ฐ”๊พธ๊ธฐ

๋„ํ˜„์ด๋Š” ๋ฐ”๊ตฌ๋‹ˆ๋ฅผ ์ด N๊ฐœ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ , ๊ฐ๊ฐ์˜ ๋ฐ”๊ตฌ๋‹ˆ์—๋Š” 1๋ฒˆ๋ถ€ํ„ฐ N๋ฒˆ๊นŒ์ง€ ๋ฒˆํ˜ธ๊ฐ€ ์ˆœ์„œ๋Œ€๋กœ ์ ํ˜€์ ธ ์žˆ๋‹ค. ๋ฐ”๊ตฌ๋‹ˆ๋Š” ์ผ๋ ฌ๋กœ ๋†“์—ฌ์ ธ ์žˆ๊ณ , ๊ฐ€์žฅ ์™ผ์ชฝ ๋ฐ”๊ตฌ๋‹ˆ๋ฅผ 1๋ฒˆ์งธ ๋ฐ”๊ตฌ๋‹ˆ, ๊ทธ ๋‹ค์Œ ๋ฐ”๊ตฌ๋‹ˆ๋ฅผ 2

www.acmicpc.net


์„ฑ๊ณต ํ’€์ด

let NM = readLine()!.split(separator:  " ").map { Int($0)! }
let N = NM[0], M = NM[1]
var arr = Array(1...N)
for _ in 0..<M {
    let i = readLine()!.split(separator: " ").map { Int($0)!-1 }
    let b = i[0], m = i[2], e = i[1]
    let nums = arr[m...e]
    arr.removeSubrange(m...e)
    arr.insert(contentsOf: nums, at: b)
}
arr.forEach { print($0,terminator: " ") }