-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16120.h
44 lines (37 loc) · 852 Bytes
/
16120.h
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
44
#include <iostream>
#include <stack>
using namespace std;
string str;
stack<char> S;
int main_16120() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> str;
int s = str.size();
for(int i=0;i<s;i++){
S.push(str[i]);
if(S.size() >= 4){
char a0 = S.top(); S.pop();
char a1 = S.top(); S.pop();
char a2 = S.top(); S.pop();
char a3 = S.top(); S.pop();
if(a3 == 'P'
&& a2 == 'P'
&& a1 == 'A'
&& a0 == 'P'){
S.push('P');
}
else{
S.push(a3);
S.push(a2);
S.push(a1);
S.push(a0);
}
}
}
if(S.size() == 1 && S.top() == 'P')
cout << "PPAP";
else
cout << "NP";
return 0;
}