CF628B 1300

题意

解析

末尾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;
}
posted @ 2023-03-09 10:01  Isaac233  阅读(16)  评论(0)    收藏  举报