-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16120.cpp
More file actions
43 lines (38 loc) · 1.01 KB
/
16120.cpp
File metadata and controls
43 lines (38 loc) · 1.01 KB
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
39
40
41
42
43
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
string arr;
stack<int> state;
int is_ppap = 0;
int i;
cin >> arr;
state.push(0);
if (arr[0] == 'P') {
for (i = 1; i < arr.size(); i++) {
if (state.top() == 0) {
if (arr[i] == 'A') break;
else state.push(1);
}
else if (state.top() == 1) {
if (arr[i] == 'P') state.push(1);
else state.push(2);
}
else {
if (arr[i] == 'A') break;
else {
for (int j = 0; j < 3; j++) state.pop();
if (state.empty()) state.push(0);
else state.push(1);
}
}
}
}
if (!state.empty() && state.size() == 1 && state.top() == 0 && i == arr.size()) cout << "PPAP\n";
else cout << "NP\n";
return 0;
}