Skip to content

Instantly share code, notes, and snippets.

@kurianbenoy
Created June 15, 2019 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurianbenoy/ed2a0e51f628d43521847bf7e7cc1bbd to your computer and use it in GitHub Desktop.
Save kurianbenoy/ed2a0e51f628d43521847bf7e7cc1bbd to your computer and use it in GitHub Desktop.
#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