2017CCPC 秦皇岛 E

贪心

 

 

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define up rt,rt<<1,rt<<1|1
#define mem(x) memset(x,0,sizeof(x))
#define mem1(x) memset(x,-1,sizeof(x))
#define LMissher
using namespace std;
typedef long long ll;
typedef double db;
const int M = 2e5+7;
const double pi = acos(-1);
const int inf = 2147483647;
const int mod = 1e9+7;

int _,n,ans;
char s[M];
int main(){
    #ifdef LMissher
        freopen("1.in","r",stdin);
        freopen("1.out","w",stdout);
    #endif
    scanf("%d",&_);
    while(_--){
        ans=0;
        scanf("%d%s",&n,s);
        for(int i=2;i<n-1;i++){
            if(s[i]=='P'){
                if(s[i-1]=='C'&&s[i-2]=='C'&&s[i+1]=='C') ans++;
            }
        }
        if(s[0]=='C'&&s[1]=='P'&&s[2]=='C'){
            printf("%d\n",ans+1);continue;
        }
        if(s[n-1]=='C'&&s[n-2]=='C'&&s[n-3]=='C'){
            printf("%d\n",ans+1);continue;
        }
        if(s[n-1]=='P'&&s[n-2]=='C'&&s[n-3]=='C'){
            printf("%d\n",ans+1);continue;
        }
        int flg=0;
        for(int i=0;i<n-3;i++){
            if(s[i]=='C'&&s[i+1]=='C'&&s[i+2]=='P'&&s[i+3]=='P') flg=1;
            if(s[i]=='P'&&s[i+1]=='C'&&s[i+2]=='P'&&s[i+3]=='C') flg=1;
            if(s[i]=='C'&&s[i+1]=='C'&&s[i+2]=='C'&&s[i+3]=='C') flg=1;
        }
        if(flg) printf("%d\n",ans+1);
        else printf("%d\n",ans);
    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/LMissher/p/9632824.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值