From d0372f7608f0a7c67960e9df3b174b2f1659c8e7 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Fri, 27 Aug 2021 20:09:43 +0800 Subject: [PATCH] =?UTF-8?q?830.=20=E5=8D=95=E8=B0=83=E6=A0=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/7415280/ --- AcWing/830/830.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 AcWing/830/830.cpp diff --git a/AcWing/830/830.cpp b/AcWing/830/830.cpp new file mode 100644 index 00000000..95d74700 --- /dev/null +++ b/AcWing/830/830.cpp @@ -0,0 +1,22 @@ +#include + +using namespace std; + +int n, a; +stack st; + +int main() { + cin >> n; + for (int i = 0; i < n; i++) { + cin >> a; + while (!st.empty() && st.top() >= a) st.pop(); + if (st.empty()) { + cout << -1 << ' '; + } else { + cout << st.top() << ' '; + } + st.push(a); + } + cout << endl; + return 0; +}