Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings a.

The Cossack considers every substring of length f(b,c).

For example, let c=11000. In these strings, the first, second, third and fourth positions are different.

Vus the Cossack counts the number of such substrings even.

For example, let 00010.

  • f(00110,01100)=2;
  • f(00110,11000)=4;
  • f(00110,10001)=4;
  • f(00110,00010)=1.

Since in three substrings, 3.

Vus can not find the answer for big strings. That is why he is asking you to help him.

Input

The first line contains a binary string 1≤|a|≤106) — the first string.

The second line contains a binary string 1≤|b|≤|a|) — the second string.

Output

Print one number — the answer.

Examples
input
Copy
01100010
00110
output
Copy
3
input
Copy
1010111110
0110
output
Copy
4

 

 题意:
给出一个01字符串a,一个01字符串b,将a中每一个长度和b相等的子串取出,问有多少个子串,和b对应位置上数字不同的个数是偶数。
 
思路:
使用异或运算即可。
充分利用异或可交换的性质。
 
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>

#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define debug(a, x) cout<<#a<<"["<<x<<"] = "<<a[x]<<endl;
#define ls (t<<1)
#define rs ((t<<1)|1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1000086;
const int maxm = 100086;
const int inf = 0x3f3f3f3f;
const ll Inf = 999999999999999999;
const int mod = 1000000007;
const double eps = 1e-6;
const double pi = acos(-1);

char a[maxn],b[maxn];

int main() {
//    ios::sync_with_stdio(false);
//    freopen("in.txt", "r", stdin);


    scanf("%s%s",a,b);
    int lena = strlen(a);
    int lenb = strlen(b);

    int ans=0;
    for(int i=0;i<lenb;i++){
        ans^=(a[i]-48)^(b[i]-48);
    }

    int sum=0;
    if(!ans){sum++;}

    for(int i=lenb;i<lena;i++){
        ans^=(a[i]-48)^(a[i-lenb]-48);
        if(!ans){sum++;}
    }
    printf("%d",sum);




    return 0;
}
View Code

 

相关文章:

  • 2021-11-22
  • 2021-06-13
  • 2021-05-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
  • 2021-11-06
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-04
  • 2021-07-09
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案