목록swift 알고리즘/큐, 덱 (6)
쥐수의 공부노트

정답 : let n = Int(readLine()!)! for _ in 0.. tail { break } } if head > tail { print("error") } else { if check { print("[\(array[head..

정답 : var input = readLine()!.split(separator: " ").map{Int($0)!} var number = readLine()!.split(separator: " ").map{Int($0)!} let n = input[0] let m = input[1] var array = [Int](1...n) var result = 0 while !number.isEmpty { if array.first! == number.first! { array.removeFirst() number.removeFirst() continue } let startDistance = array.firstIndex(of: number.first!)! let endDistance = array.count ..
해당 문제는 다른 카테고리에서 진행했습니다. https://jisssuu.tistory.com/174 백준 10866번 덱 정답 : let n = Int(readLine()!)! var array : [Int] = [] for _ in 0.. jisssuu.tistory.com 해당 사이트를 참고해주세요!!!

정답 : let input = readLine()!.split(separator: " ").map{Int($0)!} let n = input[0] let k = input[1] var head = 0 var array = [Int](1...n) var result : [Int] = [] for i in 0..

정답 : let n = Int(readLine()!)! var head = 0 var tail = n - 1 var array : [Int] = [] for i in 1...n { array.append(i) } while true { if head == tail { break } head += 1 var num = array[head] array.append(num) head += 1 tail += 1 } print(array[head]) 더보기 TMI : head와 tail을 이용하면 쉽게 풀린다!

문제 자체는 바로 이전에 작성한 10845번 큐 문제와 동일하지만, 시간에 제한이 있다. 인터넷에는 Swift에서는 입출력이 느리기 때문에, 그것에 대한 문제도 있고, print에 문제가 있다고 나온다.. 그래서 다른 사람의 풀이를 참고하여 진행하였고.. 나중에 시간이 나게 되면 다시 보도록 하자.. import Foundation // 빠른 입력 FileIO final class FileIO { private var buffer:[UInt8] private var index: Int init(fileHandle: FileHandle = FileHandle.standardInput) { buffer = Array(fileHandle.readDataToEndOfFile())+[UInt8(0)] // 인덱스..