题意
解析
末尾2位是4的倍数即可。每次特判最后一位。
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
string s;
bool check(string str){
int x = 0;
for(int i=0;i<str.size();i++)
x = x * 10 + str[i] - '0';
if(x % 4 == 0) return true;
return false;
}
int main(){
cin >> s;
ll cnt = 0;
if(s[0] == '0' || s[0] == '4' || s[0] == '8') cnt++;
for(int i=1;i<s.size();i++){
if(check(s.substr(i-1,2))){
cnt += i;
}
if(s[i] == '0' || s[i] == '4' || s[i] == '8') cnt++;
// cout << endl << i << ' ' << s[i] << " " << cnt << endl;
}
cout << cnt;
return 0;
}
标签:1300,string,int,ll,long,CF628B
From: https://www.cnblogs.com/dtdbm/p/17197302.html