Created
June 15, 2019 17:04
-
-
Save kurianbenoy/ed2a0e51f628d43521847bf7e7cc1bbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<math.h> | |
using namespace std; | |
int main() | |
{ | |
int T,D=0; | |
//string str; | |
int cp=0,p; | |
float r; | |
cin>>T; | |
while(T--) | |
{ | |
p=0,cp=0,r=0.0; | |
cin>>D; | |
char str[2000]; | |
for(int i=0;i<D;i++) | |
cin>>str[i]; | |
// count the occurence of P | |
for(int i=0;i<D;i++) | |
{ | |
if(str[i]=='P') | |
cp++; | |
} | |
r = 0.75*D - cp; | |
for(int i=2;i<D-2;i++) | |
{ | |
if((str[i]=='A') && (str[i-1]=='P'|| str[i-2]=='P') && (str[i+1]=='P'|| str[i+2]=='P')) | |
{ | |
p++; | |
// cout<<i; | |
} | |
} | |
// cout<<"Actual:"<<p<<endl; | |
if(p>=r && r>0) | |
cout<<ceil(r)<<endl; | |
else | |
cout<<-1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment