From 01ab18dd502d454ab214c0af982689024c1737ab Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Fri, 27 Aug 2021 17:18:17 +0800 Subject: [PATCH] =?UTF-8?q?827.=20=E5=8F=8C=E9=93=BE=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/7412150/ --- AcWing/827/827.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 AcWing/827/827.cpp diff --git a/AcWing/827/827.cpp b/AcWing/827/827.cpp new file mode 100644 index 00000000..5d4d8cf4 --- /dev/null +++ b/AcWing/827/827.cpp @@ -0,0 +1,39 @@ +#include + +using namespace std; + +int m, x, k, p; +string op; +list a; +list::iterator it[100005]; + +int main() { + cin >> m; + while (m--) { + cin >> op; + if (op == "L") { + cin >> x; + a.push_front(x); + it[++p] = a.begin(); + } else if (op == "R") { + cin >> x; + a.push_back(x); + it[++p] = --a.end(); + } else if (op == "D") { + cin >> k; + a.erase(it[k]); + } else if (op == "IL") { + cin >> k >> x; + it[++p] = a.insert(it[k], x); + } else { + cin >> k >> x; + auto itk = it[k]; + it[++p] = a.insert(++itk, x); + } + } + for (int i : a) { + cout << i << ' '; + } + cout << endl; + return 0; +}