Skip to content

Commit

Permalink
Add 16120.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiyabye committed Jun 9, 2024
1 parent 16e2440 commit 29c894b
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions 16xxx/16120.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
#include <stack>
#include <string>
using namespace std;

bool solve(void) {
string s; cin >> s;

stack<char> 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;
}

0 comments on commit 29c894b

Please sign in to comment.