-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1406번.swift
38 lines (33 loc) · 900 Bytes
/
1406번.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// 출처 : 백준 에디터
// https://www.acmicpc.net/problem/1406
// 풀이 : hogumachu
import Foundation
let inputString: String = readLine()!
var inputStringArray = inputString.map{ $0 }
let inputNum: Int = Int(readLine()!)!
var cursor: Int = inputStringArray.count
for _ in 0..<inputNum {
let order: String = readLine()!
switch order {
case "L":
if cursor > 0 {
cursor -= 1
}
case "D":
if cursor < inputStringArray.count {
cursor += 1
}
case "B":
if cursor == 0 {
} else {
inputStringArray.remove(at: cursor - 1)
cursor -= 1
}
default:
let str = order.split(separator: " ")
inputStringArray.insert(contentsOf: "\(str[1])", at: cursor)
cursor += 1
}
}
var result = inputStringArray.reduce("", {String($0) + String($1)})
print(result)