mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
7a2a9109f5
2600-2699
167 lines
4.7 KiB
C++
167 lines
4.7 KiB
C++
#include<stdio.h>
|
|
#include<string.h>
|
|
int main()
|
|
{
|
|
char nek[1000],bf[1000];
|
|
int i,j,l,k;
|
|
int as,bs,c1,c2;
|
|
int ap,bp;
|
|
int max;
|
|
int t;
|
|
while(scanf("%d",&t)!=EOF)
|
|
{
|
|
while(t--)
|
|
{
|
|
max=0;
|
|
as=0;
|
|
bs=1;
|
|
scanf("%s",nek);
|
|
strcpy(bf,nek);
|
|
l=strlen(nek);
|
|
while(bs<l)
|
|
{
|
|
ap=bp=0;
|
|
c1=0;
|
|
c2=0;
|
|
for(i=as;;i--)
|
|
{
|
|
if(i<0)
|
|
{
|
|
i=l-1;
|
|
}
|
|
if(nek[i]=='a')
|
|
break;
|
|
if(nek[i]=='w')
|
|
{
|
|
nek[i]='a';
|
|
c1++;
|
|
}
|
|
if(nek[i]=='p')
|
|
{
|
|
if(ap==0||ap==1)
|
|
{
|
|
nek[i]='a';
|
|
ap=1;
|
|
c1++;
|
|
}else
|
|
break;
|
|
}
|
|
if(nek[i]=='r')
|
|
{
|
|
if(ap==0||ap==2)
|
|
{
|
|
nek[i]='a';
|
|
ap=2;
|
|
c1++;
|
|
}else
|
|
break;
|
|
}
|
|
}
|
|
for(j=bs;;j++)
|
|
{
|
|
if(j==l)
|
|
{
|
|
j=0;
|
|
}
|
|
if(nek[j]=='a')
|
|
break;
|
|
if(nek[j]=='w')
|
|
{
|
|
nek[j]=='a';
|
|
c2++;
|
|
}
|
|
if(nek[j]=='p')
|
|
{
|
|
if(bp==0||bp==1)
|
|
{nek[j]=='a';
|
|
bp=1;
|
|
c2++;
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
if(nek[j]=='r')
|
|
{
|
|
if(bp==0||bp==2)
|
|
{nek[j]=='a';
|
|
bp=2;
|
|
c2++;
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
}
|
|
if(max<c1+c2)
|
|
{
|
|
max=c1+c2;
|
|
}
|
|
strcpy(nek,bf);
|
|
c1=c2=0;
|
|
ap=bp=0;
|
|
as++;
|
|
bs++;
|
|
}
|
|
c1=c2=0;
|
|
ap=bp=0;
|
|
as=bs=1;
|
|
for(i=l-1,j=0;i>j;i--,j++)
|
|
{
|
|
if(nek[i]=='w'&&as)
|
|
{
|
|
c1++;
|
|
}
|
|
if(nek[j]=='w'&&bs)
|
|
{
|
|
c2++;
|
|
}
|
|
if(nek[i]=='p'&&as)
|
|
{
|
|
if(ap==0||ap==1)
|
|
{
|
|
ap=1;
|
|
c1++;
|
|
}else
|
|
{as=0;
|
|
}
|
|
}
|
|
if(nek[j]=='p'&&bs)
|
|
{
|
|
if(bp==0||bp==1)
|
|
{
|
|
bp=1;
|
|
c2++;
|
|
}else
|
|
{
|
|
bs=0;
|
|
}
|
|
}
|
|
if(nek[i]=='r'&&as)
|
|
{
|
|
if(ap==0||ap==2)
|
|
{
|
|
ap=2;
|
|
c1++;
|
|
}else
|
|
as=0;
|
|
}
|
|
if(nek[j]=='r'&&bs)
|
|
{
|
|
if(bp==0||bp==2)
|
|
{
|
|
bp=2;
|
|
c2++;
|
|
}else
|
|
{
|
|
bs=0;
|
|
}
|
|
}
|
|
}
|
|
if(max<c1+c2)
|
|
{
|
|
max=c1+c2;
|
|
}
|
|
printf("%d\n",max);
|
|
}
|
|
}
|
|
}
|