链接: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;
}