题目链接:http://codeforces.com/problemset/problem/628/B点击打开链接
求多少个子串是4的倍数
因为100是4的倍数
因此先计算子串长度为1的有多少个 (注意0也是) 然后计算长度为2的 因为长度为2的+n*100也是4的倍数 加上该子串前面有几个 就能全部算出来 用longlong
#include <iostream>
#include <stdio.h>
#include <limits.h>
#include <stack>
#include <algorithm>
#include <queue>
#include <string.h>
#include <set>
using namespace std;
int main()
{
string s;
cin >> s;
long long int cnt=0;
for(int i=0;i<s.length();i++)
{
if((s[i]-'0')%4==0)
{
cnt++;
}
if(i!=0)
{
if(((s[i]-'0')+(s[i-1]-'0')*10)%4==0)
cnt+=(i);
}
}
cout << cnt;
}