From 29c894b35a914852d7b9423035ea2b16f12aeb59 Mon Sep 17 00:00:00 2001 From: Jihoon Lee Date: Sun, 9 Jun 2024 22:56:41 +0900 Subject: [PATCH] Add 16120.cpp --- 16xxx/16120.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 16xxx/16120.cpp diff --git a/16xxx/16120.cpp b/16xxx/16120.cpp new file mode 100644 index 00000000..8edd9e5a --- /dev/null +++ b/16xxx/16120.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +using namespace std; + +bool solve(void) { + string s; cin >> s; + + stack st; + for (char c : s) { + if (st.empty() || c == 'A' || st.size() < 3) { + st.push(c); + } else { + char b = st.top(); st.pop(); + char a = st.top(); st.pop(); + if (b == 'A' && a == 'P' && st.top() == 'P') { + st.pop(); + st.push('P'); + } else { + st.push(a); + st.push(b); + st.push(c); + } + } + } + return st.size() == 1 && st.top() == 'P'; +} + +int main(void) { + ios::sync_with_stdio(false); + cin.tie(nullptr); + + cout << (solve() ? "PPAP" : "NP"); + return 0; +} \ No newline at end of file