-
Notifications
You must be signed in to change notification settings - Fork 10
/
PROXY.cpp
54 lines (50 loc) · 1.1 KB
/
PROXY.cpp
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
45
46
47
48
49
50
51
52
53
54
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define For(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i <= b;i++)
#define Rfor(i,n) for(int i = n-1;i >= 0;i--)
#define endl '\n'
#define pb push_back
#define mp make_pair
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
string s;
cin>>s;
// cout<<s<<endl;
int f = 0;
int ans = 0;
int p_count = (int)count(s.begin(), s.end(),'P');
if(float(p_count)/float(n) >= 0.75)
{
cout<<ans<<endl;
}
else
{
for(int i =2;i<n-2;i++)
{
// cout<<p_count<<endl;
if(s[i] == 'A' && (s[i-1] == 'P' || s[i-2] == 'P') && (s[i+1] == 'P' || s[i+2] == 'P'))
{
p_count += 1;
ans++;
}
// cout<<p_count<<endl;
if(float(p_count)/float(n) >= 0.75)
{
f = 1;
// cout<<ans<<endl;
break;
}
}
f == 1?cout<<ans<<endl:cout<<-1<<endl;
}
}
return 0;
}