codeforce 1186 C——Vus the Cossack and Strings

链接:https://codeforces.com/contest/1186/problem/C

题目大意:给你两个串S和T,将T与所有S串长度为|T|的子串比较,问你不匹配字符个数为偶数个的个数是多少?

第一遍直接判断是奇是偶,然后每次在S串中向前移一位的,判断最新位和之前被最后一位是否相同,相同则奇偶性相同,否则翻转。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
using namespace std;

const int maxn=1e6+10;
char s[maxn],t[maxn];
int main(){
    scanf("%s",s);
    scanf("%s",t);
    //首先比较一轮
    int ans=0,temp=0;
    int inx;
    for(inx=0;inx<strlen(t);inx++){
        if(t[inx]!=s[inx])
            temp++;
    }
    if(temp%2==0)ans++;
    int len=strlen(t);
    for(int i=len;i<strlen(s);i++){
        if(s[i]==s[i-len]){
            if(temp%2==0)ans++;
        }
        else{
            temp+=1;
            if(temp%2==0)ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值